RegEx to select everything between two characters?

前端 未结 4 641
野的像风
野的像风 2020-12-28 13:06

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 everythi

相关标签:
4条回答
  • 2020-12-28 13:52

    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 !

    0 讨论(0)
  • 2020-12-28 14:07

    For a simple case this should do:

    §(.*);
    

    It might need to be modified if you don't want to allow nesting:

    §(.*?);
    
    0 讨论(0)
  • 2020-12-28 14:09

    Use this regex

    (?<=§).*?(?=;)
    
    0 讨论(0)
  • 2020-12-28 14:10

    How about

    "§([^;]*);"
    

    The selected characters between the § and ; are available as match group 1.

    0 讨论(0)
提交回复
热议问题