Perl-based Regular Expression Pattern
(Redirected from Perl Regular Expression Statement)
		
		
		
		Jump to navigation
		Jump to search
		A Perl-based Regular Expression Pattern is a regular expression pattern expressed in a Perl language.
- AKA: Perl Regular Expression.
- Context:
- It can be used in a Perl-based Regular Expression Replace Statement, such as s/a([bc])d/x$1y/g;.
- …
 
- It can be used in a Perl-based Regular Expression Replace Statement, such as 
- Example(s):
- …
 
- Counter-Example(s):
- See: Perl Coding Notes, Regular Expression Statement.
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 afollowed by any single character (not newline) followed by acfollowed by a period | 
| a?b*c+ | zero or one as followed by zero or morebs followed by one or morecs. | 
| ^abc|abc$ | the string abcat the beginning or at the end of the string | 
| ab{2,4}c | an afollowed by two, three or fourb’s followed by ac | 
| ab{2,}c | an afollowed by at least twob’s followed by ac | 
| .{81,} | a line with at least 80 chars | 
| [abc] | any one of a,bandc | 
| [Aa]bc | either of Abcandabc | 
| [abc]+ | any (nonempty) string of a’s,b’s andc’s(such asa,abba,acbabcacaa) | 
| [^abc]+ | any (nonempty) string which does not contain any of a,bandc(such asdefg) | 
| \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 fooand12bar8andfoo_1 | 
| 100\s*mk | the strings 100andmkoptionally separated by any amount of white space (spaces, tabs, newlines) | 
| abc\b | abcwhen followed by a word boundary (e.g. inabc!but not inabcd) | 
| perl\B | perlwhen not followed by a word
boundary (e.g. inperlertbut not inperl stuff) | 
References
2011
- http://en.wikipedia.org/wiki/Regular_expression#Perl-derivative_regular_expressions
- Perl has a more consistent and richer syntax than the POSIX basic (BRE) and extended (ERE) regular expression standards. An example of its consistency is that \always escapes a non-alphanumeric character. Other examples of functionality possible with Perl but not POSIX-compliant regular expressions is the concept of lazy quantification (see the next section), possessive quantifies to control backtracking, named capture groups, and recursive patterns. … many other utilities and programming languages have adopted syntax similar to Perl's — for example, Java, JavaScript, PCRE, Python, Ruby, Microsoft's .NET Framework, and the W3C's XML Schema all use regular expression syntax similar to Perl's.
 
- Perl has a more consistent and richer syntax than the POSIX basic (BRE) and extended (ERE) regular expression standards. An example of its consistency is that