哪些字符可用作正则表达式定界符? [英] Which characters can be used as regular expression delimiters?

查看:150
本文介绍了哪些字符可用作正则表达式定界符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪些字符可以用作Perl正则表达式的定界符? m/re/m(re)måreå似乎都可以,但是我想知道所有可能性.

Which characters can be used as delimiters for a Perl regular expression? m/re/, m(re) and måreå all seem to work, but I'd like to know all possibilities.

推荐答案

来自 perlop :

使用m可以将任意一对非空白字符用作定界符.

With the m you can use any pair of non-whitespace characters as delimiters.

因此,除空格外,其他所有操作均无效.全文如下:

So anything goes, except whitespace. The full paragraph for this is:

如果"/"是定界符,则首字母m是可选的.使用m时,可以将任意一对非空白字符用作定界符.这对于匹配包含"/"的路径名特别有用,以避免LTS(倾斜牙签综合症).如果 "?"是定界符,然后是"PATTERN"的仅匹配一次"规则适用.如果'"是定界符,则不对PATTERN执行插值.当使用在标识符中有效的字符时,在m后面需要空格.

If "/" is the delimiter then the initial m is optional. With the m you can use any pair of non-whitespace characters as delimiters. This is particularly useful for matching path names that contain "/", to avoid LTS (leaning toothpick syndrome). If "?" is the delimiter, then the match-only-once rule of ?PATTERN? applies. If "'" is the delimiter, no interpolation is performed on the PATTERN. When using a character valid in an identifier, whitespace is required after the m.

这篇关于哪些字符可用作正则表达式定界符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆