Link to home
Create AccountLog in
Avatar of dkim18
dkim18

asked on

regular expression in c#

Hi,

I need help with parsing this kind of lines:
I would like to grab
1) text before open parenthesis ( if no parenthesis, just grab everything)
2) text inside of the parenthesis if there is a parenthsis.

First I am going to split them by line and then grab those two texts.
I was using the indexof('(') and would to like use the regular expression.

My Monitored Questions (dd2323232, 343434, and d343434)
My Topics( 20 )
My Participated Questions
You have not participated in any questions that have had activity in the past 6 months. View More (g343434, c343434, g343443)
My Topics (ccc20)
My Knowledgebase (558 )
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

1) text before open parenthesis ( if no parenthesis, just grab everything)
2) text inside of the parenthesis if there is a parenthsis.

Both can be grabbed with a single pattern:
^([^(\n]*)(?:\(([^)\n]*))?
Avatar of dkim18
dkim18

ASKER

this seems to grab everything except a closing paren.
I tested it in the regex validator also.
ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account