I have to split a string which contains normal values as well as currency values
i.e. aaa,bbb,$33,222,ccc,$22,000
Output expected :
-aaa
-bbb
-$33,222
-ccc
-$22,000
Just split according to the below regex.
@",(?!\d)"
This will match all the commas which are not followed by a digit. (?!\d)
asserts that the match must not be followed by a digit.
In c# this should work.
@"(?<!\$\d+),(?!\d+)"
Just giving a non-regex answer for some variety. You could do the following:
This replaces the currency commas with full stops or whatever you want so that you can comfortably split the string on commas. You can always change it back to commas once you have the tokens. Note that this only works under the assumptions that currency values will always have decimals.