I need some help with regular expression.
I need to search for “Android 2.2.x” where x can be 1-9 in a string so I created this RegEx
Androind 2.2.\d{1} This works fine.
Now I want to find Android 2.2 in the in the string
If I search using Regex “Androind 2.2” it matches both “Android 2.2” and “Android 2.2.x” But I want regex to match only “Android 2.2”
Can anyone please help me with this.
Thanks,
Use negative lookahead.
"Android 2.2(?!\.\d)"matches"Android 2.2"but not"Android 2.2.1","Android 2.2.2","Android 2.2.10", etc. It will also match"Android 2.2."if the next character is not a digit or the end of thestringis reached.See Grouping Constructs for more information.