Tüm örnekleri eşleştirilmiş parantezleri bir dizeden kaldırmak için C# normal ifadelerinin nasıl kullanılacağını anlamaya çalışıyorum. Parantez ve aralarındaki tüm metinler kaldırılmalıdır. Parantezler her zaman aynı satırda değildir. Ayrıca, yuvalanmış parantez olabilir. dizesi örneği aşağıdaki gibi arzu edilen çıkış olmalıdırC# Regex - Birden çok eşli parantezin dizgiden nasıl kaldırılacağı
This is a (string). I would like all of the (parentheses
to be removed). This (is) a string. Nested ((parentheses) should) also
be removed. (Thanks) for your help.
olacaktır: In
Regex regexObj = new Regex(
@"\( # Match an opening parenthesis.
(?> # Then either match (possessively):
[^()]+ # any characters except parentheses
| # or
\((?<Depth>) # an opening paren (and increase the parens counter)
| # or
\) (?<-Depth>) # a closing paren (and decrease the parens counter).
)* # Repeat as needed.
(?(Depth)(?!)) # Assert that the parens counter is at zero.
\) # Then match a closing parenthesis.",
RegexOptions.IgnorePatternWhitespace);
: Neyse
This is a . I would like all of the . This a string. Nested also
be removed. for your help.
İstediğiniz çıktıyı ekleyebilir misiniz? –
Elbette. Gönderiyi güncelleyeceğim. –
... ya da buraya: http://stackoverflow.com/questions/133601/can-regular-expressions-be-used-to-match-nested-patterns –