Perl-based Regular Expression Pattern

From GM-RKB
Jump to navigation Jump to search

A Perl-based Regular Expression Pattern is a regular expression pattern expressed in a Perl language.



Examples

Jukka Korpela Examples

http://www.cs.tut.fi/~jkorpela/perl/regexp.html
expression matches...
abc abc (that exact character sequence, but anywhere in the string)
a.c\. an a followed by any single character (not newline) followed by a c followed by a period
a?b*c+ zero or one as followed by zero or more bs followed by one or more cs.
^abc|abc$ the string abc at the beginning or at the end of the string
ab{2,4}c an a followed by two, three or four b’s followed by a c
ab{2,}c an a followed by at least two b’s followed by a c
.{81,} a line with at least 80 chars
[abc] any one of a, b and c
[Aa]bc either of Abc and abc
[abc]+ any (nonempty) string of a’s, b’s and c’s (such as a, abba, acbabcacaa)
[^abc]+ any (nonempty) string which does not contain any of a, b and c (such as defg)
\d\d any two decimal digits, such as 42; same as \d{2}
\w+ a “word”: a nonempty sequence of alphanumeric characters and low lines (underscores), such as foo and 12bar8 and foo_1
100\s*mk the strings 100 and mk optionally separated by any amount of white space (spaces, tabs, newlines)
abc\b abc when followed by a word boundary (e.g. in abc! but not in abcd)
perl\B perl when not followed by a word boundary (e.g. in perlert but not in perl stuff)


References

2011