Sei sulla pagina 1di 1

I I regularexpressions

Anchors
A
Start of llne +
\A Start of strtng +
$ End of llne +
\Z End of strlng +
\ b Word boundary +
\6 Not word boundary +
\< Start of word
\> End of word
Charactcr Classcs
\e Control character
\ S Whlte space
\S Not white space
\ d Olglt
\0 Not dlgl t
\ W Word
\ W Not word
\xhh Hexadecimal character hh
\OX>O< Octal character xxx
POSIX Charactcr Classes
[:upper:] Upper case letters
[:lower:] Lower case letters
[:alpha: J All letters
[ :alnum: ] Olglts and l etters
[:di gi t:] Olglts
[:xdi gi t:] Hexadecimal dlgits
[:punct:] Punctuatlon
[ : blank: ] Space and t ab
[: spaee: J 61ank characters
[ :entr1: ) Control charact ers
[:g ... ph:) Pri nted characters
[ : print : ) Prlnted charact ers and
spaces
[:word: ) Oigits, l etters and
underscore
Asscrtions
?= Lookahead assertion +
?1 l ookahead +
?<= Lookbehtnd assertlon +
?!= or ?<! l ookbehlnd +
?> Once-only Subexpression
?() Condl tlon [ 11 then]
?()1 Condition ( if then else)
?# Comment
Jtems markecl + should work in most
regular expression i mplementations,
Sample Patterns
([A-Za-z0-9-]+)
(\d{ 1,2}V\d{ 1,2}V\d { 4} l
([ A\s)+( ?=\.(Jpglglll png))\.\2)
(A [ 1-9]{ 1} $1 A[ 1-4 J { 1 }[ 0-9]{ 1 }$1 ASO$)
( #?([A-Fa-10-9 )){3} ( ([ A-Fa-f0-9)){3} )?)
((?=. *\d)(?=. *[a-z])(?=. *[A-ZJ).{8,15})
(\w+@[ a-ZA-Z_] + ?\.( a-ZA-Z] { 2,6})
(\<(/?[A\>]+)\>)
Letters, numbers and hyphens
Dat e (e.g. 21/3/2006)
jpg, gif or png image
Any number from 1 t o so Inclusi ve
Val id hexadecimal col our code
8 to 15 character strlng wlth at l east one
upper case letter, one l ower case letter,
and one digi t (useful for passwords).
Email addresses
HTML
These pattems are inrended for reference purposes and ha ve not been extensively tested.
Please LISe with caution and test thoroughly before use,
Quantifiers R.anges
O or more + Any character except
? O or more, ungreedy + new line (\n) +
+ 1 or more + (alb) a or b +
+? 1 or more, ungreedy + ( ... ) Group +
? O or 1 + (?: ... ) Passl ve Group +
?? O or 1, ungreedy + [abe) Range (a or b or e) +
{3} Exactly 3 + [A abe) Not aorborc +
{3,} 3 or more + [a-q) Letter bet\veen a and q +
{3,5} 3
1
4 or 5 + [A-QJ Upper case letter +
{3, 5}? 3, 4 or 5, ungreedy + between A and Q +
[0- 7] Oigit between O and 7 +
Spcdal Charnctcrs
\n nth group/subpattern +
\ Escape Character +
\n New l lne +
111 Ranges are WJus;ve.
\ r Carriage return +
\t Tab +
Pattcrn Modifiors
\V Vertical t ab +
\1 Form f ee<l +
9
Gl obal mat ch
\a Al arm Case-lnsensl tJve
[\bl 6ackspace m Mul tiple lines
\ e Escape S Treat strlng as single llne
\N{name} Named Character X Allow comments and
white space In pattern
String Rcplacemcnt (Bac:krefcrc:nces)
Evaluate replacement
u Ungreedy pattem
sn nth non-passl ve group
$2 "xyz" In fA(abe(xyz))$/
SI "xyz" In fA(?: abe)(xyz)$/
Metacharactcrs (must be cscaped)
s' 6efore mat ched strlng
A
[
S' After mat ched str ing $ {
$+ Last matched string ( \ +
s&. Entlre mat ched string ) ?
s_ Entlre Input string < >
S$ literal"$"
Avallab/e free from
AddedBytes.com

Potrebbero piacerti anche