c# - Regex capturing group terminating early -


i don't ask dumb regex questions. here's 1 regex vultures....

take these strings...

-this nice (show cow) *this (or that) (show mouse) -whatever -hiya (everyone) 

all these should match. ie lead * or -, text, can conditionally followed whitespace , (show xxx) xxx can text. want these captured separately ie...

-this nice (show cow)    match 1 : 'this nice'    match 2 : '(show cow)' or 'cow'  *this (or that) (show mouse)    match 1 : 'this (or that)'    match 2 : 'show mouse' or 'mouse'  -whatever    match 1 : 'whatever'  -hiya (everyone)    match 1 : 'hiya (everyone)'  +hello    no match 

i have tried variously...

[\-*](.+?)(\s+\(show (.+)\))?     terminates , captures 1 char of match 1  [\-*](.+)(\s+\(show (.+)\))?     terminates late , captures of text match 1 including `(show....`  [\-*](.+)(\s+\(show (.+)\)$)?     above 

i'm sure should easy! don't want go negating (show within match 1 - permit eg -hello (show a) (show b) match 1 hello (show a) , match 2 (show b) (or b)

i think want this,

^[-*](.*?)(?: \(show\s*([^)]*)\)|$) 

demo


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -