Textwrangler grep正则表达式参考?

7
我正在寻找一份详尽的表格/列表,其中包含Textwrangler中使用的正则表达式。手册很好,但缺乏概述,无法用于快速参考备忘单。谢谢;)

1
为什么这个有用的已经回答的问题被关闭为不适合主题,而不是被迁移到Super User? - Jacob C.
1个回答

11

点击这里

以下是我挑选出来的部分:

模式修饰符(开关)

i             Case-insensitive
m             Multiline   : allow the grep engine to match at  ^ and $ after and before at \r or \n.
s             Magic Dot   : allows . to match \r and \n
x             Free-spacing: ignore unescaped white space; allow inline comments in grep patterns.

(?imsx)       On
(?-imsx)      Off
(?i-msx)      Mixed

正则表达式元字符:

.             Any character except newline or carriage return
[ ]           Any single character of set
[^ ]          Any single character NOT of set
*             0 or more previous regular expression
*?            0 or more previous regular expression (non-greedy)
+             1 or more previous regular expression
+?            1 or more previous regular expression (non-greedy)
?             0 or 1 previous regular expression
|             Alternation
( )           Grouping regular expressions
^             Beginning of a line or string
$             End of a line or string
{m,n}         At least m but most n previous regular expression
{m,n}?        At least m but most n previous regular expression (non-greedy)
\1-9          Nth previous captured group
\&            Whole match                                     # BBEdit: '&' only - no escape needed
\`            Pre-match                                       # PCRE?  NOT BBEdit
\'            Post-match                                      # PCRE?  NOT BBEdit
\+            Highest group matched                           # PCRE?  NOT BBEdit
\A            Beginning of a string
\b            Backspace(0x08)(inside[]only)                   # PCRE?
\b            Word boundary(outside[]only)
\B            Non-word boundary
\d            Digit, same as[0-9]
\D            Non-digit

大小写转换运算符

\E            Change case - acts as an end delimiter to terminate runs of \L & \U.
\l            Change case of only the first character to the right lower case. (Note: lowercase 'L')
\L            Change case of all text to the right to lowercase.
\u            Change case of only the first character to the right to uppercase.
\U            Change case of all text to the right to uppercase.

White-Space or Non-White-Space

\t            Tab
\n            Linefeed
\r            Return
\f            Formfeed
\s            Whitespace character equivalent to [ \t\n\r\f]
\S            Non-whitespace character

\W            Non-word character
\w            Word character[0-9A-Za-z_]
\z            End of a string
\Z            End of a string, or before newline at the end
(?#)          Comment
(?:)          Grouping without backreferences
(?=)          Zero-width positive look-ahead assertion
(?!)          Zero-width negative look-ahead assertion
(?>)          Nested anchored sub-regexp stops backtracking
(?imx-imx)    Turns on/off imx options for rest of regexp
(?imx-imx:…)  Turns on/off imx options, localized in group    # '…' indicates added regex pattern

更多信息请查看链接的文档。


太棒了!!谢谢!现在我明白了,它像Perl,哈哈...有点像。我正在编写非常长的正则表达式,想知道能否在它们上面加注释...嗯,在?imsx模式下,你甚至可以给意大利面式的表达式添加漂亮的格式:)太酷了!(我不能投票支持你,因为我还需要一些声望分:() - runlevel0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接