Is it faster to use alternation than subsequent replacements in regular expressions

前端 未结 6 527
耶瑟儿~
耶瑟儿~ 2021-01-05 17:27

I have quite a straightforward question. Where I work I see a lot of regular expressions come by. They are used in Perl to get replace and/or get rid of some strings in text

6条回答
  •  日久生厌
    2021-01-05 17:50

    Second method is best in which you put first and second regex together with alternation. Because in that method the perl do traverse once, and check both the expressions.

    If you use first method in which perl have to traverse separate for both expressions.

    Hence Number of loops decreased in Second method.

提交回复
热议问题