vaheeD khoshnouD

linux, mikrotik, macosx

Regular Expressions

Written by vaheeD on December 28, 2012
4.00 avg. rating (84% score) - 1 vote


Patterns of characters that are used in searching databases

Metacharacter Meaning Example Explanation
. Exactly one character, not null . One character, not null.
* zero or more times (like {0,}) ab*c ac, abc, abbc, abbbc, …
+ once or more times (like {1,}) ab+c abc, abbc, abbbc, …
? zero or once (like {0,1}) ab?c ac,abc.
^ Beginning of the line ^abc Lines witch begin with “abc”.
$ End of the line abc$ Lines witch end with “abc”.
\ Escape carahcter \. dot character.
[] One occurence of list [abc] matches a,b or c.
[-] Range of characters [a-d] matches a,b,c or d.
[^] Reverse range of characters [^a-d] matches not a,b,c or d.
(|) alternative text (abc|def) matches abc or def.
\d exactly one digit \d\d 00, 01, …, 99.
\D everything except digit \D\D not 00,…,99.
\w exactly one letter,number or underscore (like [A-z0-9_]) \w a, 1, _, ….
\W everything except letter, number or underscore(like [^A-z0-9_]) \W @,#,…
\s exactly one whitespace (space,tab,newline) \s
\S everything except whitespace \S @
\b word boundary \bdef def (not abcdef)
\B non-word boundary \Bdef abcdef (not def)
\t tab character
\n carriage return
\nnn octal number \007 bell character
{m} character repetitions (m times) a{2} aa
{m,n} character repetitions (minimum m, maximum n) a{2,3} aa,aaa
{m,} character repetitions (minimum m) a{2,} aa,aaa,aaaa,aaaaa,…

 

4.00 avg. rating (84% score) - 1 vote

Posted Under: Linux, Macosx

About vaheeD

Leave a Reply

Your email address will not be published. Required fields are marked *

Protected by WP Anti Spam