Regex and escaped and unescaped delimiter

前端 未结 5 1555
我寻月下人不归
我寻月下人不归 2020-12-18 00:38

question related to this

I have a string

a\\;b\\\\;c;d

which in Java looks like

String s = \"a\\\\;b\\\\\\\\;c;d\"         


        
5条回答
  •  情话喂你
    2020-12-18 01:16

    This is the real answer i think. In my case i am trying to split using | and escape character is &.

        final String regx = "(?

    In this code i am using Lookbehind to escape & character. note that the look behind must have maximum length.

    (?

    this means any | except those that are following ((?:[^&]|^)(&&){0,10000}&)) and this part means any odd number of &s. the part (?:[^&]|^) is important to make sure that you are counting all of the &s behind the | to the beginning or some other characters.

提交回复
热议问题