Regex question

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
 
K

Kevin Spencer

((?<!\?)\+)|((?<!\?)')

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.
 
K

Kevin Spencer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top