i’ve tried to read the apple documentation but i’ll never use regular expression and i do not understand how to solve this matter.
I need to write a regular expression for check if the user has selected a string that match with this rules:
first letter could be s or S and it’s optional
second chars could be a . (char dot) and it’s optional
4 number digit could from 1 to 4 and must be always present
after the number could be present any single char from a-z and could be optional
after i can have a . (char dot) and it’s optional
the last 2 must be a digit must be always 2 number and could be optional
i tried to write in this way
NSString *regexStr = @"(s|S)?(\\.)?(\\d+){,4}([a-z]?(\\.)?(\\d+){2}?";
but the console give this error
Error making regex: Error Domain=NSCocoaErrorDomain Code=2048
"The operation couldn’t be completed. (Cocoa error 2048.)" UserInfo=0x6d3e9b0
{NSInvalidValue=(s|S)?(\.)?(\d+){,4}([a-z]?(\.)?(\d+){2}?}
Anyone could help me?
Thanks!
Here you go:
You had an extra opening parenthesis that made the syntax invalid, and
+signs after the\ds, that made the regexp accept infinite numbers of digits.Regexpal is great for debugging regexps: http://regexpal.com/