Copyright (1997-2013) EDMGROUP Pty Ltd - EZY Prolog Reference

 EZY Regular Expressions

main page

 

EZY Prolog has built-in support for regular expressions.

 

Below is sample of EZY Prolog programs which demonstrates how to use regular expressions and regular expressions results.

Click here for program source

 

Output of the regular expressions test

 

 


Regular expression results

String:

Results:

Regular Expression:

2DEVELOP VISION AND STRATEGY

Syntax: awk, Found: {2} at position 1, length 1

-?([0-9]+((\.)[0-9]+)+)|([0-9]+)

1.1.0 UNDERSTAND MARKETS AND inside the text

Syntax: awk, Found: {1.1.0} at position 1, length 5

-?[0-9]+((\.)[0-9]+)+

Valid Integer -93334

Syntax: emacs, Found: {-93334} at position 15, length 6

-?[0-9]+

Intel Pentium 4E, 3000 MHz

Syntax: emacs, Found: {3000 MHz} at position 19, length 8

-?[0-9]+ MHZ

Valid Real Value +734.11e-1234

Syntax: awk, Found: {+734.11e-1234} at position 18, length 13

(\+|-)?[0-9]*\.[0-9]*([Ee](\+|-)?[0-9]+)

URL in form http://www.ser.com/dir/file.htm

Syntax: awk, Found: {http://www.ser.com/dir/file.htm} at position 13, length 31

http:+(\\|//)+([a-zA-Z_0-9.]*+(\\|/))+([a-zA-Z_0-9]*).htm*

Valid Phone number (415)-999-8888

Syntax: posix_awk, Found: {(415)-999-8888} at position 38, length 14

(\([0-9]{3}\))+(-| )+([0-9]{3})+(-| )+([0-9]{4})

Valid Phone number (415) 999-8888

Syntax: posix_awk, Found: {(415) 999-8888} at position 38, length 14

(\([0-9]{3}\))+(-| )+([0-9]{3})+(-| )+([0-9]{4})

Valid date DD Month Year 12 February 2001

Syntax: posix_awk, Found: {12 February 2001} at position 44, length 19

([0-9]{2})([ ]+)([a-z]+)([ ]+)([1-2]([0-9]{3}))

Valid date MM-DD-YYYY 02/02/2000

Syntax: posix_awk, Found: {02/02/2000} at position 41, length 10

([0-1][0-2](\\|/|-|.))([0-9]{2}(\\|/|-|.))([1-2][0-9]{3})

Valid date MM-DD-YYYY 12-02/2000

Syntax: posix_awk, Found: {12-02/2000} at position 41, length 10

([0-1][0-2](\\|/|-|.))([0-9]{2}(\\|/|-|.))([1-2][0-9]{3})

Invalid date MM-DD-YYYY 22/02/2000

{Invalid date MM-DD-YYYY 22/02/2000 } failed

([0-1][0-2](\\|/|-|.))([0-9]{2}(\\|/|-|.))([1-2][0-9]{3})

Chapter followed by a single whitespace character (space, tab, newline, etc), followed by a single digit Chapter 9 bla-bla

Syntax: emacs, Found: {Chapter 9} at position 106, length 9

Chapter+[ ][0-9]

Chapter followed by a space, followed by a word character

Syntax: emacs, Found: {Chapter followed} at position 1, length 16

Chapter+[ ]\w*

Line with march 12 1999 or mar 12 1999

Syntax: posix_awk, Found: {march 12 1999} at position 29, length 13

((jan[a-z]*)|(feb[a-z]*)|(mar[a-z]*)|(apr[a-z]*)|(may)|(ju[a-z]*)|(aug[a-z]*)|(sep[a-z]*)|(oct[a-z]*)|(nov[a-z]*)|(dec[a-z]*))+([ ]+|\.|-)+([0-9]{2}([ ]+|.|-))(([1-2][0-9]{3})|[0-9]{2})

Text with march 12, 99 or march 12, 99

{Text with march 12, 99 or march 12, 99 } failed

((jan[a-z]*)|(feb[a-z]*)|(mar[a-z]*)|(apr[a-z]*)|(may)|(ju[a-z]*)|(aug[a-z]*)|(sep[a-z]*)|(oct[a-z]*)|(nov[a-z]*)|(dec[a-z]*))+([ ]+|\.|-)+([0-9]{2}([ ]+|.|-))(([1-2][0-9]{3})|[0-9]{2})

Para with mar 12, 1999 or mar 12, 99

{Para with mar 12, 1999 or mar 12, 99 } failed

((jan[a-z]*)|(feb[a-z]*)|(mar[a-z]*)|(apr[a-z]*)|(may)|(ju[a-z]*)|(aug[a-z]*)|(sep[a-z]*)|(oct[a-z]*)|(nov[a-z]*)|(dec[a-z]*))+([ ]+|\.|-)+([0-9]{2}([ ]+|.|-))(([1-2][0-9]{3})|[0-9]{2})

04:30 pm

{04:30 pm} failed

(d{1,2}):(\d\d)\s*(am|pm|\s*)

12:45am

{12:45am} failed

(\d{1,2}):(\d\d)\s*(am|pm|\s*)

14:45

{14:45} failed

(\d{1,2}):(\d\d)\s*(am|pm|\s*)

matches a string that has an a followed by exactly two b's abb

Syntax: posix_awk, Found: {abb} at position 78, length 3

ab{2}

there are at least two b's "abb", "abbbb", etc.)

Syntax: posix_awk, Found: {abb} at position 47, length 3

ab{2,}

from three to five b's ("abbb", "abbbb", or "abbbbb")

Syntax: posix_awk, Found: {abbb} at position 44, length 4

ab{3,5}

a possible a followed by one or more b's ending a string

Syntax: emacs, Found: {b} at position 8, length 1

a?b+

matches a string that has an a followed by zero or more copies of the sequence bc

Syntax: awk, Found: {a} at position 2, length 1

a(bc)*

one through five copies of bc such as abcbc

Syntax: posix_awk, Found: {abcbc} at position 64, length 5

a(bc){1,5}

matches a string that has either hi or hello in it;

Syntax: awk, Found: {hi} at position 52, length 2

hi|hello

a string that has either bef or cdef

Syntax: awk, Found: {bef} at position 44, length 3

(b|cd)ef

a string that has bc sequence of alternating a's and b's ending in a c

Syntax: awk, Found: {c} at position 25, length 1

(a|b)*c

a string that has ac sequence of alternating a's and b's ending in a c

Syntax: awk, Found: {c} at position 25, length 1

(a|b)*c

matches a string that has an a followed by one character and a digit a0234

Syntax: emacs, Found: {a02} at position 88, length 3

a.[0-9]

matches a string that has an a followed by one character and a digit a0234

Syntax: emacs, Found: {a023} at position 88, length 4

a..[0-9]

a string with exactly 5 characters

Syntax: posix_awk, Found: {a str} at position 1, length 5

.{5}

a string that has a single digit before a percent sign 6%

Syntax: emacs, Found: {6%} at position 74, length 2

[0-9]%

a string that ends in a comma followed by an alphanumeric character ,C

Syntax: emacs, Found: {,C} at position 87, length 2

,[a-zA-Z0-9]

matches a string with a character that is not a letter between two percent signs %6%

Syntax: emacs, Found: {%6%} at position 100, length 3

%[^a-zA-Z]%

money as $10000.00

Syntax: awk, Found: {$10000} at position 10, length 6

$([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(\.[0-9]{1,2})?

money as $10,000.00

Syntax: awk, Found: {$10} at position 10, length 3

$([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(\.[0-9]{1,2})?

money without the cents: $10000

Syntax: awk, Found: {$10000} at position 26, length 6

$([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(\.[0-9]{1,2})?

money without the cents: $10,000

Syntax: awk, Found: {$10} at position 26, length 3

$([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(\.[0-9]{1,2})?

MS DOS file names c:file.txt

Syntax: emacs, Found: {c:file.txt} at position 19, length 10

\([A-Za-z]\:\)\([A-Za-z]+\)\.\([A-Za-z]+\)

Find email address username@servername.com

Syntax: awk, Found: {username@servername.com} at position 38, length 23

[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*

Find email address name.department@servername.com

Syntax: awk, Found: {name.department@servername.com} at position 38, length 30

[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*

Chapter X, Chapter 1, bla-bla-bla

Syntax: emacs, Found: {Chapter 1} at position 12, length 9

Chapter [0-9]

Chapter 1, Chapter X, bla-bla-bla

Syntax: emacs, Found: {Chapter X} at position 12, length 9

Chapter [^0-9]

ax, bx, aax, abx, bax, bbx, aaax, aabx, abax, abbx, baax, babx, bbax, bbbx, aaaax ....

Syntax: emacs, Found: {ax} at position 1, length 2

a+x

ax, bx, cx, dx, ex

Syntax: emacs, Found: {ax} at position 1, length 2

[abcde]x

ax, bx, cx, dx, ex

Syntax: emacs, Found: {ax} at position 1, length 2

[a-e]x

ax, bx, cx, dx, ex

Syntax: emacs, Found: {ax} at position 1, length 2

[-ae]x

-x, ax, ex

Syntax: emacs, Found: {-x} at position 1, length 2

[ae-]x

-x, ax, ex,

Syntax: emacs, Found: {-x} at position 2, length 2

[ae-]x

ax, cx, ex

{ax, cx, ex} failed

[a-e-[bd]]x

any non-digit character followed by the character ZY6x ZCVx BBB

Syntax: emacs, Found: {Vx} at position 59, length 2

[^0-9]x

any digit character followed by the character ZY6x ZCVx BBB

Syntax: emacs, Found: {6x} at position 50, length 2

[0-9]x

any non-digit character followed by the character Bx9 BBxF

{ any non-digit character followed by the character Bx9 BBxF} failed

\Dx

1x2abc, abc1x2, z3456abchooray ....

Syntax: emacs, Found: {1x2abc, abc1x2, z3456abchooray ....} at position 1, length 35

.*abc.*

two digits 98 bbbb

Syntax: emacs, Found: {98} at position 12, length 2

[0-9][0-9]

abbx

Syntax: posix_awk, Found: {abbx} at position 1, length 4

ab{2}x

abbx, abbbx, abbbbx

Syntax: posix_awk, Found: {abbx} at position 1, length 4

ab{2,4}x

abbx, abbbx, abbbbx ....

Syntax: posix_awk, Found: {abbx} at position 1, length 4

ab{2,}x

ababx

Syntax: posix_awk, Found: {ababx} at position 1, length 5

(ab){2}x

aaabc

Syntax: emacs, Found: {aaa} at position 1, length 3

a*

abc

Syntax: emacs, Found: {abc} at position 1, length 3

abc

xbc

{xbc} failed

abc

axc

{axc} failed

abc

abx

{abx} failed

abc

xabcy

Syntax: emacs, Found: {abc} at position 2, length 3

abc

ababc

Syntax: emacs, Found: {abc} at position 3, length 3

abc

abc

Syntax: emacs, Found: {abc} at position 1, length 3

ab*c

abc

Syntax: emacs, Found: {abc} at position 1, length 3

ab*bc

abbc

Syntax: emacs, Found: {abbc} at position 1, length 4

ab*bc

abbbbc

Syntax: emacs, Found: {abbbbc} at position 1, length 6

ab*bc

abbc

Syntax: emacs, Found: {abbc} at position 1, length 4

ab+bc

abc

{abc} failed

ab+bc

abq

{abq} failed

ab+bc

abbbbc

Syntax: emacs, Found: {abbbbc} at position 1, length 6

ab+bc

abbc

Syntax: emacs, Found: {abbc} at position 1, length 4

ab?bc

abc

Syntax: emacs, Found: {abc} at position 1, length 3

ab?bc

abbbbc

{abbbbc} failed

ab?bc

abc

Syntax: emacs, Found: {abc} at position 1, length 3

ab?c

abc

Syntax: emacs, Found: {abc} at position 1, length 3

^abc$

abcc

{abcc} failed

^abc$

abcc

Syntax: emacs, Found: {abc} at position 1, length 3

^abc

aabc

{aabc} failed

^abc$

aabc

Syntax: emacs, Found: {abc} at position 2, length 3

abc$

abc

{abc} failed

^

abc

{abc} failed

$

abc

Syntax: emacs, Found: {abc} at position 1, length 3

a.c

axc

Syntax: emacs, Found: {axc} at position 1, length 3

a.c

axyzc

Syntax: emacs, Found: {axyzc} at position 1, length 5

a.*c

axyzd

{axyzd} failed

a.*c

abc

{abc} failed

a[bc]d

abd

Syntax: emacs, Found: {abd} at position 1, length 3

a[bc]d

abd

{abd} failed

a[b-d]e

ace

Syntax: emacs, Found: {ace} at position 1, length 3

a[b-d]e

aac

Syntax: emacs, Found: {ac} at position 2, length 2

a[b-d]

a-

Syntax: emacs, Found: {a-} at position 1, length 2

a[-b]

a-

Syntax: emacs, Found: {a-} at position 1, length 2

a[b-]

ab

{ab} failed

[k]

-

{-} failed

a[b-a]

-

{-} failed

a[]b

-

{-} failed

a[

a]

Syntax: emacs, Found: {a]} at position 1, length 2

a]

a]b

Syntax: emacs, Found: {a]b} at position 1, length 3

a[]]b

aed

Syntax: emacs, Found: {aed} at position 1, length 3

a[^bc]d

abd

{abd} failed

a[^bc]d

adc

Syntax: emacs, Found: {adc} at position 1, length 3

a[^-b]c

a-c

{a-c} failed

a[^-b]c

a]c

{a]c} failed

a[^]b]c

adc

Syntax: emacs, Found: {adc} at position 1, length 3

a[^]b]c

abc

Syntax: awk, Found: {ab} at position 1, length 2

ab|cd

abcd

Syntax: awk, Found: {ab} at position 1, length 2

ab|cd

def

Syntax: awk, Found: {ef} at position 2, length 2

()ef

-

{-} failed

()*

-

{-} failed

*a

-

{-} failed

^*

-

{-} failed

$*

-

{-} failed

(*)b

b

{b} failed

$b

-

{-} failed

a\

a(b

Syntax: awk, Found: {a(b} at position 1, length 3

a\(b

ab

Syntax: awk, Found: {ab} at position 1, length 2

a\(*b

a((b

Syntax: awk, Found: {a((b} at position 1, length 4

a\(*b

a\b

Syntax: emacs, Found: {a\b} at position 1, length 3

a\\b

-

{-} failed

abc)

-

{-} failed

(abc

abc

Syntax: awk, Found: {a} at position 1, length 1

((a))

abc

Syntax: awk, Found: {abc} at position 1, length 3

(a)b(c)

aabbabc

Syntax: emacs, Found: {abc} at position 5, length 3

a+b+c

-

{-} failed

a**

-

{-} failed

a*?

-

{-} failed

(a*)*

-

{-} failed

(a*)+

-

{-} failed

(a|)*

-

{-} failed

(a*|b)*

ab

Syntax: awk, Found: {ab} at position 1, length 2

(a+|b)*

ab

Syntax: awk, Found: {ab} at position 1, length 2

(a+|b)+

ab

Syntax: awk, Found: {a} at position 1, length 1

(a+|b)?

cde

Syntax: emacs, Found: {cde} at position 1, length 3

[^ab]*

-

{-} failed

(^)*

-

{-} failed

(ab|)*

-

{-} failed

)(

abc

{abc} failed

 

 

{} failed

abc

 

{} failed

a*

abcd

Syntax: emacs, Found: {abcd} at position 1, length 4

abcd

abcd

Syntax: awk, Found: {abcd} at position 1, length 4

a(bc)d

abbbcd

Syntax: awk, Found: {abbbcd} at position 1, length 6

([abc])*d

abcd

Syntax: awk, Found: {abcd} at position 1, length 4

([abc])*bcd

e

Syntax: awk, Found: {e} at position 1, length 1

a|b|c|d|e

ef

Syntax: awk, Found: {ef} at position 1, length 2

(a|b|c|d|e)f

-

{-} failed

((a*|b))*

abcdefg

Syntax: emacs, Found: {abcdefg} at position 1, length 7

abcd*efg

xabyabbbz

Syntax: emacs, Found: {ab} at position 2, length 2

ab*

xayabbbz

Syntax: emacs, Found: {a} at position 2, length 1

ab*

abcde

Syntax: awk, Found: {cde} at position 3, length 3

(ab|cd)e

hij

Syntax: emacs, Found: {hij} at position 1, length 3

[abhgefdc]ij

abcde

{abcde} failed

^(ab|cd)e

abcdef

Syntax: awk, Found: {ef} at position 5, length 2

(abc|)ef

abcd

Syntax: awk, Found: {bcd} at position 2, length 3

(a|b)c*d

abc

Syntax: awk, Found: {abc} at position 1, length 3

(ab|ab*)bc

abc

Syntax: awk, Found: {abc} at position 1, length 3

a([bc]*)c*

abcd

Syntax: awk, Found: {abcd} at position 1, length 4

a([bc]*)(c*d)

abcd

Syntax: awk, Found: {abcd} at position 1, length 4

a([bc]+)(c*d)

abcd

Syntax: awk, Found: {abcd} at position 1, length 4

a([bc]*)(c+d)

adcdcde

Syntax: emacs, Found: {adcdcde} at position 1, length 7

a[bcd]*dcdcde

adcdcde

{adcdcde} failed

a[bcd]+dcdcde

abc

Syntax: awk, Found: {abc} at position 1, length 3

(ab|a)b*c

abcd

Syntax: awk, Found: {abcd} at position 1, length 4

((a)(b)c)(d)

abcy

Syntax: emacs, Found: {abc} at position 1, length 3

[ -~]*

abc

Syntax: emacs, Found: {abc} at position 1, length 3

[ -~ -~]*

abc

Syntax: emacs, Found: {abc} at position 1, length 3

[ -~ -~ -~]*

abc

Syntax: emacs, Found: {abc} at position 1, length 3

[ -~ -~ -~ -~]*

abc

Syntax: emacs, Found: {abc} at position 1, length 3

[ -~ -~ -~ -~ -~]*

abc

Syntax: emacs, Found: {abc} at position 1, length 3

[ -~ -~ -~ -~ -~ -~]*

abc

Syntax: emacs, Found: {abc} at position 1, length 3

[ -~ -~ -~ -~ -~ -~ -~]*

alpha

Syntax: emacs, Found: {alpha} at position 1, length 5

[a-zA-Z_][a-zA-Z0-9_]*

abh

Syntax: awk, Found: {bh} at position 2, length 2

^a(bc+|b[eh])g|.h$

effgz

Syntax: awk, Found: {effgz} at position 1, length 5

(bc+d$|ef*g.|h?i(j|k))

ij

Syntax: awk, Found: {ij} at position 1, length 2

(bc+d$|ef*g.|h?i(j|k))

effg

{effg} failed

(bc+d$|ef*g.|h?i(j|k))

bcdd

{bcdd} failed

(bc+d$|ef*g.|h?i(j|k))

reffgz

Syntax: awk, Found: {effgz} at position 2, length 5

(bc+d$|ef*g.|h?i(j|k))

-

{-} failed

((((((((((a))))))))))

a

Syntax: awk, Found: {a} at position 1, length 1

(((((((((a)))))))))

uh-uh

{uh-uh} failed

multiple words of text

multiple words, yeah

Syntax: emacs, Found: {multiple words} at position 1, length 14

multiple words

abcde

Syntax: awk, Found: {abcde} at position 1, length 5

(.*)c(.*)

(a, b)

Syntax: awk, Found: {(a, b)} at position 1, length 6

\((.*), (.*)\)

 

Copyright 1997-2013 EDMGROUP (Australia)

 

Last Updated:

October 26, 2008