superlurker
superlurker

Reputation: 13

RegEx to match a pattern

The problem I'm having is, I don't want to match to have a comma preceding the first match number..

Ex: "1,2,3 <?>" and "0,9,1,2 <?>"

What I have now is @"\d,\d,\d\s*<?>" and It returns this "1,2,3 <?>" and "9,1,2 <?>". It shouldn't get the "9,1,2 <?>" because it has a 0, in front... How do I exclude this match?

Upvotes: 0

Views: 51

Answers (1)

hwnd
hwnd

Reputation: 70732

Use the beginning of string ^ and end of string $ anchors and escape the ? metacharacter.

@"^\d,\d,\d\s*<\?>$"

Live Demo

Upvotes: 2

Related Questions