tags:

views:

18

answers:

1

Hi ive got this regular expression and that extracts numbers from a string

string.Join(null,System.Text.RegularExpressions.Regex.Split(expr, "[^\\d]"));

so eg, the format of my string is like this strA:12, strB:14, strC:15

so the regex returns 121415

how can I modify the expression to return 12,14,15 instead, any suggestions please

+1  A: 

You're calling String.Join, which joins an array of strings into a single string, separating each element by the separator parameter.

Since you're passing null as that parameter, it doesn't put anything between the strings.

You need to pass ", " instead of null to separate each string with ,.

SLaks
Thanks I understand the code, the problem is it sort of works but not quite as I get this 2,,,,,,,,,1,,,,,2,,,,,,,, as opposed to 2,1,2
dominic
Change the regex to `@"[^\d]+"`.
SLaks
Thanks it worked
dominic