Reputation: 7354
I need to ignore a '.' at the start of my regular expression, and have been somewhat stumped.
My current regex is:
(?::)(\d{3})
Which matches the following:
When I try to ignore the '.' with the following regex:
[^.](?::)(\d{3})
I get this:
As it seems to be adding the extra character like '<', which is unwanted.
How do I go about to ignore that extra character in front of the ':' ?
Upvotes: 4
Views: 10402
Reputation: 174696
Just use a lookahead to match the strings in this :\d{3}
format preceded by any but not of dot.
(?=[^.](:(\d{3})))
Group 1 contains the string with :
, and the group 2 contains only the digits.
Upvotes: 1
Reputation: 785038
Use this alternation based regex:
\.:\d{3}|:(\d{3})
And grab captured group #1 for your matches.
Upvotes: 2