Regex question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!

I want to create a regex (using C#) that split a String where a +: or '
character is found except if the specified character is preceeded by a ?. The
? act as a do not split here sign.

Can anyone give me a hint how to create this regex.

regards / gustav
 
((?<!\?)\+)|((?<!\?)')

This regular expression looks for either of 2 possible matches: + or '.

It uses a negative lookbehind to assert that the character is not preceded
by a ?.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 
Hi Gustav,

Yes, I didn't take the time necessary to optimize it well. But your solution
prompted me to come up with an even better one:

(?<!\?)['\+\:]

Rather than Or'ing the values together, put them into a character class.

Didn't notice the colon in the original list!

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 
Back
Top