Regex for default string splitting, multiple delimiters

I need to split a string using Regex (using VB.net) and:

  • Store the separator character in parts
  • Divide before parts.

So far I have:

Regex.Split(MyString, "(?<=[<@])")

This splitting into my two delimiters (@ and <) is fine, but I'm getting the @ or <character in the wrong part, so I need to split one step after each section we're currently getting ...

that is, it is & lt; is> a @string

currently divided into:

  • is> a @
  • line

But I want:

  • this
  • <is> a
  • @string

Any help is greatly appreciated! Regex puzzles me!

+3


source to share


1 answer


Use lookahead instead of lookbehind to split:

(?=[<@])

      



Demo version of RegEx

+2


source







All Articles