RegEx to select everything between two characters?

Viewed 123132

I am trying to write a regex that selects everything between two characters.

For example, when the regex encounters a '§' I want it to select everything after the '§' sign, up until the point that the regex encounters a ';'. I tried with a lookbehind and lookahead, but they don't really do the trick.

So for example " § 1-2 bla; " should return " 1-2 bla".

Any help would be greatly appreciated!

4 Answers

If you have multiple § (char example) use : §([^§]*)§

It will ignore everything between two § and only take what's between the 2 special char, so if you have something like §What§ kind of §bear§ is best, it will output: §what§ , §bear§

What happening? lets dissect the expression § then ([^§]*) then §

  1. 1- match § char
  2. 2- match anything but § [^§] 0 or more times *
  3. match § char

Hope it helps !

Related