S
sherifffruitfly
Hi all,
I'm new to regex, and hacked this one together. It seems awfully
redundant to me, but it does have the virtue at least of wearing its
meaning on its sleeve.
The task:
(1) match all quoted-comma'd numbers consisting of either 2 or 3
"sections". That is, critters of either form:
" "ddd,ddd,ddd" "
or
" "ddd,ddd" "
(2) Capture all of the digits, leaving the quotes and commas for the
garbage man. For example:
" "123, 456, 789" "
should in some fashion capture
"123456789"
Here's the regex I came up with:
(?<whole>\"(?<one>\d{1,3}),(?<two>\d{1,3}),(?<three>\d{1,3})\"|\"(?<one>\d{1,3}),(?<two>\d{1,3})\")
This works fine for me, and getting the desired complete "clean" number
from it is a
triviality.
But I get the feeling that this is the regex-equivalent of baby-talk.
I'd like to know if there's a simpler, more elegant regex matching the
same class of strings, and capturing essentially the same substrings.
Thanks for any insights,
cdj
I'm new to regex, and hacked this one together. It seems awfully
redundant to me, but it does have the virtue at least of wearing its
meaning on its sleeve.
The task:
(1) match all quoted-comma'd numbers consisting of either 2 or 3
"sections". That is, critters of either form:
" "ddd,ddd,ddd" "
or
" "ddd,ddd" "
(2) Capture all of the digits, leaving the quotes and commas for the
garbage man. For example:
" "123, 456, 789" "
should in some fashion capture
"123456789"
Here's the regex I came up with:
(?<whole>\"(?<one>\d{1,3}),(?<two>\d{1,3}),(?<three>\d{1,3})\"|\"(?<one>\d{1,3}),(?<two>\d{1,3})\")
This works fine for me, and getting the desired complete "clean" number
from it is a
triviality.
But I get the feeling that this is the regex-equivalent of baby-talk.
I'd like to know if there's a simpler, more elegant regex matching the
same class of strings, and capturing essentially the same substrings.
Thanks for any insights,
cdj