perl regex escape characters

后端 未结 2 771
情话喂你
情话喂你 2020-12-21 02:11

I have heard perl is a good language at doing regex but i am a bit confused at the characters that requires escaping

I tested the code on http://regexlib.com/RETeste

相关标签:
2条回答
  • 2020-12-21 02:20

    You can choose use ! instead of / to surround your regular expression so that you don't have to escape the /.

    m!//home/dev/((.*?)/[^/]+).*#!
    

    should work. Here's it in action: http://ideone.com/TDrBG

    0 讨论(0)
  • 2020-12-21 02:34

    If you're using perl you don't have to use / as the regex delimiter if you preceed the delimiter with "m" for the matching operator, or "s" for the substitution operator (e.g. you can use # or ! or even any balanced parentheses/brackets: s[this][that]), and then you don't have to escape /. You can also use the quotemeta function or \Q\E regex escape sequences that automatically escape any metacharacters.

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