I am trying to wri开发者_如何转开发te 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!
How about
"§([^;]*);"
The selected characters between the §
and ;
are available as match group 1.
Use this regex
(?<=§).*?(?=;)
For a simple case this should do:
§(.*);
It might need to be modified if you don't want to allow nesting:
§(.*?);
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- match § char
- 2- match anything but §
[^§]
0 or more times*
- match § char
Hope it helps !
精彩评论