Priority in regex manipulating

后端 未结 4 773
[愿得一人]
[愿得一人] 2021-01-26 15:28

I write some java code to split string into array of string. First, I split that string using regex pattern \"\\\\,\\\\,|\\\\,\" and then I split using pattern

4条回答
  •  盖世英雄少女心
    2021-01-26 16:22

    How regex works: The state machine always reads from left to right. ,|,, == ,, as it always will only be matched to the first alternation:


    (source: gyazo.com)

    ,,|, == ,,?:


    (source: gyazo.com)


    However, you should use ,,? instead so there's no backtracking:


    (source: gyazo.com)

提交回复
热议问题