正则表达式语法讲解(三)

      Modifiers
      修改符
 
      Modifiers are for changing behaviour of TRegExpr.
      修改符用于改变TregExpr的行为。
 
      There are many ways to set up modifiers.
      Any of these modifiers may be embedded within the regular expression itself using the (?...) construct.
      Also, You can assign to appropriate TRegExpr properties (ModifierX for example to change /x, or ModifierStr to change all modifiers together). The default values for new instances of TRegExpr object defined in global variables, for example global variable RegExprModifierX defines value of new TRegExpr instance ModifierX property.
     {TODO    下面的翻译不好,恳请指教}
      有很多方法设置修改符。
      任意这些修改符都可以使用(?...)构造器被嵌入一个正则表达式。
      同样,你可以赋予TregExpr属性合适的修改符(例如修改符X用于改变/x,或者修改符Srt用于改变所有的修改符)。TRegExpr对象的默认值定义在全局变量中,比如全局变量RegExprModifierX定义了TRegExpr的新实例的ModifierX属性的值。
 
      Do case-insensitive pattern matching (using installed in you system locale settings), see also InvertCase.
      要进行大小写敏感模式匹配(使用安装在你系统的本地配置),参见InvertCase。
 
      m
 
      Treat string as multiple lines. That is, change "^'' and "$'' from matching at only the very start or end of the string to the start or end of any line anywhere within the string, see also Line separators.
      处理多行文本。意味着,"^'' and "$''不仅匹配本行的开头和结尾,而是目标串中的任意开头和结尾,参见行分隔符。
 
      s
 
      Treat string as single line. That is, change ".'' to match any character whatsoever, even a line separators (see also Line separators), which it normally would not match.
处理目标串为单行。表示改变".''用于匹配任意字符,即使是行分隔符(参加行分隔符),正常情况下行分隔符不会被".''匹配。
 
      g
 
      Non standard modifier. Switching it Off You'll switch all following operators into non-greedy mode (by default this modifier is On). So, if modifier /g is Off then '+' works as '+?', '*' as '*?' and so on
      非标准修改符。关闭修改符,你将使下列的操作符为非贪婪模式(默认修改符使开启的)。所以,如果修改符/g关闭了,那么'+'就会等于'+?','*'等于'*?',等等。
 
      x
 
      Extend your pattern's legibility by permitting whitespace and comments (see explanation below).
      通过使用空格和注释扩展你的匹配模式的易读性。(参见下面的explanation)
 
      r
 
      Non-standard modifier. If is set then range ?� additional include russian letter '?, ?? additional include '?, and ??include all russian symbols.
      Sorry for foreign users, but it's set by default. If you want switch if off by default - set false to global variable RegExprModifierR.
      非标准修改符。如果设置非标准修改符,那么?的范围就还会包括俄国的字符'?,??还包括'?和??等所有俄文符号。
      对外国人来说很抱歉,这被设置为默认的。如果你默认要求关闭 - 设置全局变量RegExprModifierR为false即可。
 
      The modifier /x itself needs a little more explanation. It tells the TRegExpr to ignore whitespace that is neither backslashed nor within a character class. You can use this to break up your regular expression into (slightly) more readable parts. The # character is also treated as a metacharacter introducing a comment, for example:
      修改符/x需要一些更多的解释。它告诉TRegExpr忽略既不是反斜线也不是在一个字符类中的空格。你可以使用这个特性轻松地使你的正则表达式分为更多的可读部分。“#”也被认为使一个元字符用于注释中,例如:
 
      (
      (abc) # comment 1
       |    # You can use spaces to format r.e. - TRegExpr ignores it
      (efg) # comment 2
      )
 
      This also means that if you want real whitespace or # characters in the pattern (outside a character class, where they are unaffected by /x), that you'll either have to escape them or encode them using octal or hex escapes. Taken together {TODO 不晓得怎么翻译}, these features go a long way towards making regular expressions text more readable.
      这也意味着如果你要在模式中使用真正的空格或者“#”(在一个字符类外,他们可以通过加/x被忽略),你要么不得不将它们转义,或者用十进制或者十六进制表示。同时,这些特性对正在表达式文本的可读性大有帮助。
 
      Perl extensions
      Perl扩展
 
      {TODO    不知道 }
      (?imsxr-imsxr)
      You may use it into r.e. for modifying modifiers by the fly. If this construction inlined        into subexpression, then it effects only into this subexpression
 
      Examples:
       (?i)Saint-Petersburg        matchs 'Saint-petersburg' and 'Saint-Petersburg'
       (?i)Saint-(?-i)Petersburg matchs 'Saint-Petersburg' but not 'Saint-petersburg'
       (?i)(Saint-)?Petersburg     matchs 'Saint-petersburg' and 'saint-petersburg'
 
       ((?i)Saint-)?Petersburg     matchs 'saint-Petersburg', but not 'saint-petersburg'
 
 
(?#text)
A comment, the text is ignored. Note that TRegExpr closes the comment as soon as it sees a ")", so there is no way to put a literal ")" in the comment.
一个注释,文本被忽略了。注意TRegExpr只要看到")"就关闭注释,所以不能在注释中加入")"。
 
Internal mechanism explanation
 
It seems You need some internal secrets of TRegExpr?
Well, it's under constraction, please wait some time..
Just now don't forget to read the FAQ (expecially 'non-greediness' optimization question).
如果需要更多帮助,暂时无法借助internet,还是多看FAQ吧。8)

你可能感兴趣的:(职场,语法,正则,休闲)