0% found this document useful (0 votes)
71 views9 pages

Regular Expressions

how to use reg ex
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views9 pages

Regular Expressions

how to use reg ex
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Character Meaning

Example

Matches zero or one occurrence of the previous


characher

ab?c matches ac, abc

Matches zero or more occurences of the


previous character

ab*c matches ac, abbc, abc,


abbbbc

Matches one or more occurences of the


preceding character

ab+c matches abc, abbc

{N}

Matches the preceding character a specific


number of times

w{3} matches
www.Informatica.com

Specify the minimum number of matches and


maximum number of matches of the preceding
{min,max} character

60{2,5} matches
600,6000,600000

Character classes indicate a set of characters to match.

Enclosing a set of characters in square brackets "[...]" means "match


any one of these characters".

Example: to match a or e, use [ae]. To search for grey or gray the


equivalent regex is gr[ae]y. This regex will not match graey or graay.

Character Class

Meaning

[aeiou]

Matches any single character included in the specified set of


characters.

[^aeiou]

Matches any single character not in the specified set of characters.

[0-9a-fA-F]

Use of a hyphen () allows specification of contiguous character


ranges.

\w

Matches any word character. \w is equivalent to [a-zA-Z_0-9].

\W

Matches any non word character. \W is equivalent to [^a-zA-Z_0-9].

\s

Matches any white-space character.

\S

Matches any non-white-space character.

\d

Matches any decimal digit. Equivalent to [0-9]

\D

Matches any nondigit. Equivalent [^0-9]

A regular expression is a string that uses a standard syntax to define a search pattern. The syntax
is similar to a wildcard search, but with greatly enhanced search capabilities.
Consider, for example, the following text:
Peter Piper picked a peck of pickled peppers

The following are illustrations of regular expressions and the strings that they retrieve from the
above text.

Regular expression

Peter

Pip.+cked

[Pp]i[a-k]{3}

The following table lists special characters that you can use in regular expressions. The table is
not comprehensive. There are other syntax combinations that have special meanings in regular
expressions.

Character

(asterisk)

(question)

Character

(plus)

{}

(braces)

[]

(brackets)

(minus)

(period)

(caret)

(dollar)

(bar)

()

(parentheses)

(backslash)

Data Transformation uses the Regex++ implementation of regular expressions, copyright


1998-2003 by Dr. John Maddock, Version 1.33, 18 April 2000. For detailed information about
the regular expression syntax supported by this implementation, see
http://www.boost.org/doc/libs/1_37_0/libs/regex/doc/html/index.html.

For general information about regular expressions, see


http://en.wikipedia.org/wiki/Regular_expression and http://www.regularexpressions.info/index.html.

Preserving Portions of the Original Text


In the exp property, you can enclose portions of the regular expression in parentheses. In the
replacement property, you can use:
$
0
t
o
i
d
e
n
ti
f
y
t
h
e
e
n
ti
r
e
t
e
x
t
t
h
a
t
m
a
t
c
h
e
s
t
h

e
r
e
g
u
l
a
r
e
x
p
r
e
s
si
o
n
$
1
t
o
i
d
e
n
ti
f
y
t
h
e
s
u
b
st
ri
n
g
t
h
a
t
m

a
t
c
h
e
s
t
h
e
fi
r
st
p
a
r
e
n
t
h
e
si
z
e
d
p
o
rt
i
o
n
o
f
t
h
e
r
e
g
u
l
a
r
e
x
p

r
e
s
si
o
n
$
2
,
$
3
,
a
n
d
s
o
f
o
rt
h
,
t
o
i
d
e
n
ti
f
y
t
h
e
s
u
b
st
ri
n
g
s
t

h
a
t
m
a
t
c
h
t
h
e
s
e
c
o
n
d
,
t
h
ir
d
,
e
t
c.
p
a
r
e
n
t
h
e
si
z
e
d
p
o
rt
i
o
n

s
For example, suppose you set:
exp = abc([0-9]+)(def)
replacement = $1

This replaces abc5624def with 5624.


Alternatively, suppose you set:
exp = abc([0-9]+)(def)
replacement = $2ZYX$1

This replaces abc5624def with defZYX5624

You might also like