|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Regex questionHi!
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 ?. -- Show quoteHTH, Kevin Spencer Microsoft MVP Professional Numbskull Show me your certification without works, and I'll show my certification *by* my works. "Gustav" <Gus***@discussions.microsoft.com> wrote in message news:BE46439E-9C21-4BAA-A408-CFFBB038F2A6@microsoft.com... > 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 Thanks alot!
solved it myself this way (?<!\?)('|\+|:) Show quote "Kevin Spencer" wrote: > ((?<!\?)\+)|((?<!\?)') > > 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. > > "Gustav" <Gus***@discussions.microsoft.com> wrote in message > news:BE46439E-9C21-4BAA-A408-CFFBB038F2A6@microsoft.com... > > 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 > > > 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! -- Show quoteHTH, Kevin Spencer Microsoft MVP Professional Numbskull Show me your certification without works, and I'll show my certification *by* my works. "Gustav" <Gus***@discussions.microsoft.com> wrote in message news:CD33F3B7-36BF-4F4B-A582-CDAC9AF7668A@microsoft.com... > Thanks alot! > solved it myself this way (?<!\?)('|\+|:) > > "Kevin Spencer" wrote: > >> ((?<!\?)\+)|((?<!\?)') >> >> 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. >> >> "Gustav" <Gus***@discussions.microsoft.com> wrote in message >> news:BE46439E-9C21-4BAA-A408-CFFBB038F2A6@microsoft.com... >> > 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 >> >> >>
Other interesting topics
|
|||||||||||||||||||||||