U
U
ushim2014-05-23 18:47:12
Regular Expressions
ushim, 2014-05-23 18:47:12

Is it possible to specify a safe zone in regular expressions?

Good day.
Tell me, is it possible to specify a "safe zone" in C# in regular expressions, i.e. so that Regexp does not work in this zone (for example, between two arbitrary characters).
I'll give you an example.
I have a string '2+'+'3=5', it needs to be divided by pluses, but only so that the pluses in apostrophes remain there, i.e. as a result, you need an array of three elements (two parts of the string and one separator):
'2+'
+
'3=5'
First of all, the Regexp solution is of interest, but if there are alternatives, except for passing through the string and comparing, then please share.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Glebov, 2014-05-26
@IljaGlebov

Here's how I got it

foreach(var substring in Regex.Split("'2+'+'3=5'", @"'\+'").Select(s => s.Trim('\'')))
      Console.WriteLine(substring);

Result
2+
3=5

http://rextester.com/live/HMK89782

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question