What is the regex match space pattern?
I have the following values for a custom picklist field
Lower - L1
Upper - L2
Side - L3
What is the regex pattern to match the above values?
Mainly this pattern
{anylength of string}{one space}{one hyphen}{one space}{L character}{one digit integer}
I have tried something this way but not working
String message = 'Upper - L2'; String regex = '[a-zA-Z\sL\s\d{1}]*'; Pattern regexPattern = Pattern.compile(regex); Matcher regexMatcher = regexPattern.matcher(message); if(regexMatcher.matches() == true) { System.debug('Matched'); }
You have tried to make the regex match space using a character class, but that's simply incorrect.
You should find something like the following is more appropriate:
^.+ - L[0-9]$
This is:
Matching the whole value (start at the beginning with "^" and end at the end with "$")
Allowing any sequence of at least one character with ".+"
explicitly matching space, hyphen, space (this doesn't match tabs etc.)
explicitly matching "L" (this doesn't match "l")
allowing a single numeric digit between 0 and 9