哪些字符可以用作正则表达式分隔符? [英] Which characters can be used as regular expression delimiters?
问题描述
哪些字符可以用作 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屋!