Sandhurst
Sandhurst

Reputation: 1180

Regex to find a string C#

Regex to find a string in C# which starts with a space and ends with a space and have one or more commas in between.

example MELVILLE 203 31-MAR-11 15 DENNY WAY, ALFRED COVE, 6154 WA $19,040 34 POOL

Here I want to get the DENNY WAY, ALFRED COVE, 6154 WA as output

Upvotes: 1

Views: 424

Answers (3)

Toto
Toto

Reputation: 91518

I'd do:

\s[^\s,]+(,[^\s,]+?)+\s

Upvotes: 0

Aliostad
Aliostad

Reputation: 81700

Use this

 @" \S+?,\S+? "

Sure...

Upvotes: 0

Tim Pietzcker
Tim Pietzcker

Reputation: 336478

@" .*?,.*? "

You didn't mention whether spaces are also allowed inside the string. If they aren't, use

@" [^ ]*,[^ ]* "

Upvotes: 2

Related Questions