Reputation: 14787
I am trying to parse the following string and can't get the regex quite right even though it is pretty basic. I think I have the optional grouping syntax wrong. The data can be one of the following:
PV{X}
PV{X.X}
PV{X.X.X}
PV{X.X.X.X}
using:
^PV\{\d+(\.\d+){0, 3}\}$
where:
Upvotes: 0
Views: 202
Reputation: 67898
Okay, so this Regex will do it for you:
PV\{(\d+?(?:\.\d+){0,3})\}
And here is a Regex 101 to prove it.
The differences?
First, you had {0, 3}
and so it thought that was a literal value to match. You just needed to get rid of that {space}
in there. Next, the optional groups, that could occur 0 - 3
times, I dropped a ?:
in there so it doesn't actually capture that group. And then finally, I wrapped the actual value inside the { }
so that it would group that. You may want to change your groupings some, but this will surely match the entire string for you when appropriate.
Upvotes: 4