Jump to content

Regular Expressions: Difference between revisions

From EDM2
Ak120 (talk | contribs)
Ak120 (talk | contribs)
 
Line 30: Line 30:


===The Syntax of Regular Expressions===
===The Syntax of Regular Expressions===
The syntax of regular expression is basically the combination of the metacharacters and the
The syntax of regular expression is basically the combination of the metacharacters and the regular characters. For example:
regular characters. For example:
  ^My          matches line starting with the word "My"
  ^My          matches line starting with the word "My"
  finally$      matches ending with the word "finally"
  finally$      matches ending with the word "finally"
Line 37: Line 36:
  \$10          matches "$10", meaning of $ is turned off
  \$10          matches "$10", meaning of $ is turned off
  t.e          matches "t" followed by any one character and then an "e"
  t.e          matches "t" followed by any one character and then an "e"
  my*          matches "m" and followed by any number of occurances of "y"
  my*          matches "m" and followed by any number of occurrences of "y"
  th.*          matches "th" and followed by any characters including no character
  th.*          matches "th" and followed by any characters including no character
  [124]        matches one of "1" or "2" or "4"
  [124]        matches one of "1" or "2" or "4"
  [12−46]      matches one of "1" or "2" or "3" or "4" or "6". Expanded as "2−4", not twelve to fortysix.
  [12−46]      matches one of "1" or "2" or "3" or "4" or "6". Expanded as "2−4", not twelve to forty-six.
  [^abc]        matches any one except "a" and "b" and "c"
  [^abc]        matches any one except "a" and "b" and "c"


[[Category:EMX Porting FAQ]]
[[Category:EMX Porting FAQ]]

Latest revision as of 15:12, 9 November 2018

The un*x to OS/2-EMX Porting FAQ

Printing from non-PM apps

Debugging

Debugging on OS/2

Regular Expressions

The world of Regular Expressions isn't as simple as it could be: there exist many versions of them: POSIX defines Basic (BRE) and Extended Regular expressions, and in addition every language and tool tries to come up with its own enhanced set (Perl, GNU utils, emacs, ...) This an incomplete, perhaps not even correct short reference list of some common denominator of Regular Expressions. Unfortunately I have no idea where I got it from.

The Metacharacters of Regular Expressions

Character Meaning
\ Turn off the special meaning of the next character
^ Indicate the beginning of the line
$ Indicate the end of the line
. Any single character
* Any number of occurances of the previous character
[ ] Any one of the characters inside the square brackets
[^ ] Any one of the characters not inside the square brackets
\( \) Tagged regular expression

The Syntax of Regular Expressions

The syntax of regular expression is basically the combination of the metacharacters and the regular characters. For example:

^My           matches line starting with the word "My"
finally$      matches ending with the word "finally"
^I am a boy$  matches the whole line of the sentence "I am a boy"
\$10          matches "$10", meaning of $ is turned off
t.e           matches "t" followed by any one character and then an "e"
my*           matches "m" and followed by any number of occurrences of "y"
th.*          matches "th" and followed by any characters including no character
[124]         matches one of "1" or "2" or "4"
[12−46]       matches one of "1" or "2" or "3" or "4" or "6". Expanded as "2−4", not twelve to forty-six.
[^abc]        matches any one except "a" and "b" and "c"