parsing "\(|.*?)|)" - Too many )'s.
I am receving this error when writing this...
private static Regex resourceTextsREGEX = new Regex(@"\(|.*?)|)", RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase);
I want a regular expression for these two things 1- {Text} 2- |Text| I want to be able to get those matches and replace them with something ...can someone help please?
You haven't said which flavor of regex it is, but the odds are pretty high that (
and )
are grouping operators. Your expression has mis-matched parentheses:
@"\(|.*?)|)"
You might have meant
@"(|.*?\)|)" ^ ^-- escape +-- no escape
...if you're trying to create a group that may include an actual )
in it, or
@"\(|.*?\)|\)" ^ ^ ^ +-----+--+--- escapes everywhere
...if you're not trying to create a group at all, but just trying to match parens.
According to your example what you want to match you might have to want something like this
[{|](.*?)[|}]
See it here on Regexr
So you want to match
1. {Text}
2. |Text|
My regex is matching at first
[{|]
either a {
or a |
Then comes a capturing group that gets your text using a lazy match (.*?)
And at last the closing character is matched [|}]
meaning either }
or |
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With