home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / con2v766.zip / colore01.zip / doc / regexps.txt < prev    next >
Text File  |  1999-11-23  |  4KB  |  108 lines

  1.  
  2.     Colorer library regular expressions syntax description
  3.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4.  
  5.     1. It is.
  6. All  work  of  Colorer  library  is based on using regular expressions
  7. (regexp).  They let you create universal syntax rules of highlighting,
  8. but   regexp  is  an  independent  instrument,  which  could  be  used
  9. in different applications. Here you'll find description of my regexps,
  10. they limitations, secrets and other rocks of their using.
  11.     Here  I'll  assume, that you little know what is regexps - and why
  12. and  how  they used. At first I'll describe regexp's syntax, and after
  13. it  try to help you to understand them. At all you can read some other
  14. documents - perl regexps (man perlre) or something other...
  15.     My   regexps  has  one  main difference  against  the perl  -  all
  16. operators in  my  regexps  are  written  after pattern. It means, that
  17. perl-like regexp
  18.     /foo(?=bar)/
  19. in my variant will be the next:
  20.     /foo(bar)?=/
  21. May  be less looked, but more logical. All standard regexp's operators
  22. are  like  in  perl.  You  can  ask  me: why we need all this extended
  23. operators?  And  I'll answer: try to edit Hrcs an hour-two-three - and
  24. you will understand me.
  25.  
  26.     2. So, let start:
  27. All regexps must be in slashes /.../
  28. After the end slash could be a parameters:
  29.     i  -  Don't match case.
  30.     x  -  Ignore real spaces (for comfort).
  31.  
  32.     In  regexp  each  symbol  linearly  compared  with target  string.
  33. Everything,  that  not  it  the  next  symbols range means as a simple
  34. characters.
  35.  
  36.     2.1. Special metacharacters:
  37.     ^       Match the beginning of line
  38.     $       Match the end of line
  39.     .       Match any character
  40.     [ ]     Match characters in set
  41.     [^ ]    Match characters not in set
  42.             Here all the operators are disabled, but you can
  43.             use other metacharacters,  and  range  operator:
  44.             a-z means all chars from first to second (a - z)
  45.     \#      Next symbol after slash (except a-z and 1-9)
  46.     \b      Start of word
  47.     \B      End of word
  48.     \xNN    NN - ASCII char (hex)
  49.     \n      0x10 (lf)
  50.     \r      0x13 (cr)
  51.     \t      0x09 (tab)
  52.     \s      tab/space
  53.     \S      Non-space
  54.     \w      Word symbol (chars, digits, _)
  55.     \W      Non-word symbol
  56.     \d      Digit
  57.     \D      Non-Digit
  58.     \u      Uppercase symbol
  59.     \l      Lowercase symbol
  60.  
  61.     2.2. Extended metacharacters:
  62.     \c      Non-word before
  63.     \m      Change start of regexp
  64.     \M      Change end of regexp
  65.     \N      Link inside of regexp to one of its brackets.
  66.             N  - needed brackets pair.  This operator  works
  67.             only with non-operator symbols in a bracket.
  68.     \yN     Link  to  the   external  regexp (in End  to the
  69.             Start param). N - needed brackets pair.
  70.  
  71.     2.3. Operators.
  72. Here we are. They can't be used without everything. Each operator must
  73. apply to the appropriate character, metacharacter,  or block of  their
  74. combination (brackets).
  75.     ( )     Group and remember characters to form one pattern.
  76.     |       Match previous or next pattern.
  77.     *       Match previous pattern 0 or more times.
  78.     +       Match previous pattern 1 or more times.
  79.     ?       Match previous pattern 0 or 1 times.
  80.     {n}     Repeat n times.
  81.     {n,}    Repeat n or more times.
  82.     {n,m}   Repeat from n to m times.
  83. If  you  add  ?  after operator,  it becomes nongreedy.   For  example
  84. *  operator  becomes nongreedy  after substitution *? Greedy operators
  85. tries  to  take  as  much  in  string,  as  they  can. NonGreedy takes
  86. by minimum.
  87.     2.4. Extended operators.
  88.     ?#N     Look-behind. N - symbols number.
  89.     ?~N     Inverted Look-behind.
  90.     ?=      Look-ahead.
  91.     ?!      Inverted Look-ahead.
  92.  
  93.     Is it horrible? yes?
  94.  
  95.     3. And, at the end some examples.
  96. /foobar/
  97.     will match "foobar", "foobar barfoo"
  98. / FOO bar /ix
  99.     will match "foobar" "FOOBAR" "foobar and two other foos"
  100. /(foo)?bar/
  101.     will match "foobar", "bar"
  102. /^foobar$/
  103.     will match _only_ with "foobar"
  104. /([\d\.])+/
  105.     Any number
  106. /((foo)|(bar))+/
  107.     will match "foofoofoobarfoobar", "bar"
  108.