regex return conditional group
Posted
by priyank.mp
on Stack Overflow
See other posts from Stack Overflow
or by priyank.mp
Published on 2010-04-19T21:40:21Z
Indexed on
2010/04/19
21:43 UTC
Read the original article
Hit count: 981
Hi ,
I spent lot time figuring out a simple regex to return a group (only 1st group).
So the string can be - "No purchase required" or "Purchase of $50.00 worth groceries is required."
I am trying to write a regex which can parse "No" or "50" based on the given string.
This is what I have written.
(?:(No) monthly maintenance|Purchase of \$([\d\.]+ worth groceries)
This works fine but I want my output as 1st group/group 1 only.
© Stack Overflow or respective owner