I need to get from the text all the substrings limited to certain characters. If more:

In the text ( several ) times are found ( words ) in brackets. And I ( need ) to withdraw all such.


From the text above, as you might have guessed, you need to get "several", "words" and "need". Thank.

  • If the question implies any program code, please indicate at least one language tag, or any language tag - Abyx

2 answers 2

You are welcome. Here is a regular search for finding characters between brackets: \(.+?\)

enter image description here

  • Do not tell me more, you can exclude brackets by the regular schedule itself? - gremech
  • one
    Of course, you need to create one more inside the brackets, but without shielding: \((.+?)\) . Or, when processing the result of the regulars, remove the brackets themselves, even if you trim the first and last characters, even if you delete the characters themselves '(' and ')' - gil9red

Well, since C #, then I suggest this https://dotnetfiddle.net/5FUxrZ If, of course, you need to be able to process every word in any way

 using System; using System.Text.RegularExpressions; public class Program { public static void Main() { MatchCollection matches = Regex.Matches("В тексте (несколько) раз встречаются (слова) в скобках. И мне (надо) все такие изъять.", @"(\((?<Words>.+?)\))"); foreach (Match match in matches) { Group g = match.Groups["Words"]; Console.WriteLine(g.Value); } } } 

Conclusion:

 несколько слова надо