Reputation: 1961
I have a regular expression that will capture any string literal that starts with JKB and the number following it.
I have the following Reg Ex built for it:
(?'Account'JKB[0-9]+LC),(?'Amount'[0-9,.]*)
It captures the Amount
in all except the first and second from the following list:
How can I make my RegEx accommodate to capture 1st and 2nd item too; at least the number
Here is my working: https://regex101.com/r/mcQtA9/2
Upvotes: 1
Views: 45
Reputation: 626870
You need to assure the substring between the two group patterns is consumed. You can use
(?<Account>JKB[0-9]+LC),"?\s*(?<Amount>[0-9,.]*)
(?<Account>JKB[0-9]+LC),\W*(?<Amount>[0-9,.]*)
See the regex101 demo and the .NET regex demo:
I used "?\s*
in the first pattern to match an optional "
and then zero or more whitespace chars. In the second variation, I just used \W*
to match any zero or more non-word chars.
I prefer (?<name>...)
named capturing group syntax, but you may use single quoted variant, if you are more accustomed to that syntax.
Upvotes: 1