I want to check for the following strings using regExpression:
1) Main-xxxxx-Accepted 2) Main-xxx xxx-Accepted
I used the below
String regEx = 'Main-[aA-zZ-]*-Accepted';
Pattern.matches(regEx,'Main-SUBMITTED-Accepted')); results in **TRUE**
It works fine for Main-SUBMITTED-Accepted. But it fails for a word with spaces (non submitted)
Pattern.matches(regEx,'Main-NOT SUBMITTED-Accepted')); results in **FALSE**
I tried these. Nothing works
String regEx = 'Main-[aA-zZ-\\s]*-Accepted';
String regEx = 'Main-[aA-zZ-\s]*-Accepted';
How do I check for words with spaces?
[aA-zZ-\s]
means "any character that is either ana
, or a character in the rangeA
throughz
(which contains several non-letters, incidentally), or a character in the rangeZ
through\s
(which is an illegal range, apparently ignored by Salesforce).