Help with Like and Number Ranges [Square Brackets]

MartinS

Active Member
Joined
Jun 17, 2003
Messages
490
Office Version
  1. 365
Platform
  1. Windows
OK so I have a tool that needs to check the syntax of a string is in the correct format, and have been working with 'Like', but have hit a limitation which means I need to create a lot more 'templates' than I'd like. So for example:
"2021_M_(1_50%_S7_5_W1%1%)" Like "202[1-9]_[MF]_(#_##%_S#_#_W#%#%)" is True
BUT what I'd like is for the W#% to be any number between 1 and 100, but seems using the square brackets only works for single digits, i.e. [1-9] works, but [1-10] or [1-100] doesn't.
I currently have these three lines:
"2021_M_(1_50%_S7_5_W1%1%)" Like "202[1-9]_[MF]_(#_##%_S#_#_W#%#%)" Or _
"2021_M_(1_50%_S7_5_W25%25%)" Like "202[1-9]_[MF]_(#_##%_S#_#_W##%##%)" Or _
"2021_M_(1_50%_S7_5_W100%100%)" Like "202[1-9]_[MF]_(#_##%_S#_#_W###%###%)"
Is there a way to have only one 'template' for these three? Am I better off switching to regular expressions?
Many thanks
Martin
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
The bracket notation is not a number range per se, it's a range of matches for a particular character in the string, which is why you are limited to single digit options. Regex would probably be simpler here - I think you'd need three Like options for what you want.
 
Upvote 0
Solution
The bracket notation is not a number range per se, it's a range of matches for a particular character in the string, which is why you are limited to single digit options. Regex would probably be simpler here - I think you'd need three Like options for what you want.
Thanks @RoryA , helpful and as I suspected!
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,313
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top