Perl Regular Expression Cheat Sheet

  



Perlreftut Perl references short introduction perldsc Perl data structures intro perllol Perl data structures: arrays of arrays perlrequick Perl regular expressions quick start perlretut Perl regular expressions tutorial perlootut Perl OO tutorial for beginners perlperf Perl Performance and Optimization Techniques perlstyle Perl style guide. DESCRIPTION This 'cheat sheet' is a handy reference, meant for beginning Perl programmers. Not everything is mentioned, but 195 features may already be overwhelming.

  • GETTING HELP

perl - The Perl 5 language interpreter

perl[ -sTtuUWX ][ -hv ] [ -V[:configvar] ][ -cw ] [ -d[t][:debugger] ] [ -D[number/list] ][ -pna ] [ -Fpattern ] [ -l[octal] ] [ -0[octal/hexadecimal] ][ -Idir ] [ -m[-]module ] [ -M[-]'module..' ] [ -f ][ -C [number/list] ][ -S ][ -x[dir] ][ -i[extension] ][ [-e|-E] 'command' ] [ -- ] [ programfile ] [ argument ]..

For more information on these options, you can run perldoc perlrun.

The perldoc program gives you access to all the documentation that comes with Perl. You can get more documentation, tutorials and community support online at https://www.perl.org/. Reaper for mac torrent. Gtx 570 driver for mac.

  • Regular Expression Test Page for Perl. Share: Online testing with the Perl engine is still in beta. Expression to test. Regular expression: Options: multiline (m) single line (s) case-insensitive (i) Extended with whitespace and comments (x) Preserve matched strings (p).
  • Don’t forget to visit REGEX CHEAT SHEET Python, PHP, and Perl Supported Metacharacters Metacharacters Meaning a Alert b Backspace n.
  • Regular expressions in Perl This document presents a tabular summary of the regular expression (regexp) syntax in Perl, then illustrates it with a collection of annotated examples. Char meaning ^ beginning of string $ end of string. Any character except newline.

If you're new to Perl, you should start by running perldoc perlintro, which is a general intro for beginners and provides some background to help you navigate the rest of Perl's extensive documentation. Run perldoc perldoc to learn more things you can do with perldoc.

For ease of access, the Perl manual has been split up into several sections.

#Overview

#Tutorials

#Reference Manual

#Internals and C Language Interface

Perl regular expression pdf

#Miscellaneous

#Language-Specific

#Platform-Specific

#Stubs for Deleted Documents

On a Unix-like system, these documentation files will usually also be available as manpages for use with the man program.

Some documentation is not available as man pages, so if a cross-reference is not found by man, try it with perldoc. Perldoc can also take you directly to documentation for functions (with the -f switch). See perldoc --help (or perldoc perldoc or man perldoc) for other helpful options perldoc has to offer.

In general, if something strange has gone wrong with your program and you're not sure where you should look for help, try making your code comply with use strict and use warnings. These will often point out exactly where the trouble is.

Perl officially stands for Practical Extraction and Report Language, except when it doesn't.

Perl was originally a language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information. It quickly became a good language for many system management tasks. Over the years, Perl has grown into a general-purpose programming language. It's widely used for everything from quick 'one-liners' to full-scale application development.

The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal). It combines (in the author's opinion, anyway) some of the best features of sed, awk, and sh, making it familiar and easy to use for Unix users to whip up quick solutions to annoying problems. Its general-purpose programming facilities support procedural, functional, and object-oriented programming paradigms, making Perl a comfortable language for the long haul on major projects, whatever your bent.

Syntax

Perl's roots in text processing haven't been forgotten over the years. It still boasts some of the most powerful regular expressions to be found anywhere, and its support for Unicode text is world-class. It handles all kinds of structured text, too, through an extensive collection of extensions. Those libraries, collected in the CPAN, provide ready-made solutions to an astounding array of problems. When they haven't set the standard themselves, they steal from the best -- just like Perl itself.

Perl is available for most operating systems, including virtually all Unix-like platforms. See 'Supported Platforms' in perlport for a listing.

See 'ENVIRONMENT' in perlrun.

Larry Wall <larry@wall.org>, with the help of oodles of other folks.

If your Perl success stories and testimonials may be of help to others who wish to advocate the use of Perl in their applications, or if you wish to simply express your gratitude to Larry and the Perl developers, please write to perl-thanks@perl.org . Wavelab for mac crack.

'@INC' above is a reference to the built-in variable of the same name; see perlvar for more information.

Using the use strict pragma ensures that all variables are properly declared and prevents other misuses of legacy Perl features.

The use warnings pragma produces some lovely diagnostics. One can also use the -w flag, but its use is normally discouraged, because it gets applied to all executed Perl code, including that not under your control.

See perldiag for explanations of all Perl's diagnostics. The use diagnostics pragma automatically turns Perl's normally terse warnings and errors into these longer forms.

Compilation errors will tell you the line number of the error, with an indication of the next token or token type that was to be examined. (In a script passed to Perl via -e switches, each -e is counted as one line.)

Php Regular Expression Cheat Sheet

Setuid scripts have additional constraints that can produce error messages such as 'Insecure dependency'. See perlsec.

Did we mention that you should definitely consider using the use warnings pragma?

The behavior implied by the use warnings pragma is not mandatory.

Perl is at the mercy of your machine's definitions of various operations such as type casting, atof(), and floating-point output with sprintf().

If your stdio requires a seek or eof between reads and writes on a particular stream, so does Perl. (This doesn't apply to sysread() and syswrite().)

While none of the built-in data types have any arbitrary size limits (apart from memory size), there are still a few arbitrary limits: a given variable name may not be longer than 251 characters. Line numbers displayed by diagnostics are internally stored as short integers, so they are limited to a maximum of 65535 (higher numbers usually being affected by wraparound).

You may submit your bug reports (be sure to include full configuration information as output by the myconfig program in the perl source tree, or by perl -V) to https://github.com/Perl/perl5/issues.

Perl actually stands for Pathologically Eclectic Rubbish Lister, but don't tell anyone I said that.

The Perl motto is 'There's more than one way to do it.' Divining how many more is left as an exercise to the reader.

The three principal virtues of a programmer are Laziness, Impatience, and Hubris. See the Camel Book for why.

Perl

| Quick Start | Tutorial | Tools & Languages | Examples | Reference | Book Reviews |

The regular expressions reference on this website functions both as a reference to all available regex syntax and as a comparison of the features supported by the regular expression flavors discussed in the tutorial. The reference tables pack an incredible amount of information. To get the most out of them, follow this legend to learn how to read them.

The tables have six columns for each regular expression feature. The first four explain the feature.

FeatureThe name of the feature, which also serves as a link to the relevant section in the tutorial.
SyntaxThe actual regex syntax for this feature. If the syntax is fixed, it is simply shown as such. If the syntax has variable elements, the syntax is described.
DescriptionSummary of what the feature does.
ExampleFunctional regular expression that demonstrates the feature.

The final two columns indicate whether your two chosen regular expression flavors support this particular feature. You can change the flavors using the drop-down lists above the table. There are many possible indicators.

YESAll versions of this flavor support this feature.
3.0Version 3.0 and all later versions of this flavor support this feature. Earlier versions do not support it.
2.0 onlyOnly version 2.0 supports this feature. Earlier and later versions do not support it.
2.0–2.9Only versions 2.0 through 2.9 supports this feature. Earlier and later versions do not support it.
UnicodeThis feature works with Unicode characters in all versions of this flavor.
code pageThis feature works with the characters in the active code page in all versions of this flavor.
ASCIIThis feature works with ASCII characters only in all versions of this flavor.
3.0 UnicodeThis feature works with Unicode characters in versions 3.0 and later of this flavor. Earlier versions do not support it at all.
3.0 Unicode
2.0 ASCII
This feature works with Unicode characters in versions 3.0 and later this flavor. It works with ASCII characters in versions 2.0 through 2.9. Earlier versions do not support it at all.
3.0 Unicode
2.0 code page
This feature works with Unicode characters in versions 3.0 and later this flavor. It works with the characters in the active code page in versions 2.0 through 2.9. Earlier versions do not support it at all.
stringThe regex flavor does not support this syntax. But string literals in the programming language that this regex flavor is normally used with do support this syntax.
3.0
1.0 string
Version 3.0 and later of this regex flavor support this syntax. Earlier versions of the regex flavor do not support this syntax. But string literals in the programming language that this regex flavor is normally used with have supported this syntax since version 1.0.
optionAll versions of this regex flavor support this feature if you set a particular option or precede it with a particular mode modifier.
option
3.0
Version 3.0 and all later versions of this regex flavor support this feature if you set a particular option or precede it with a particular mode modifier. Earlier versions either do not support the syntax at all or do not support the mode modifier to change the behavior of the syntax to what the feature describes.
3.0
2.0 fail
Version 3.0 and all later versions of this regex flavor support this feature. Version 2.0 all later releases prior to 3.0 recognize the syntax, but always fail to match this regex token. Versions prior to 2.0 do not support the syntax.
noNo version of this flavor support this feature. No indication is given as to what this syntax actually does. The same syntax may be used for a different feature which is indicated elsewhere in the reference table. Or the syntax may trigger an error or it may be interpreted as plain text.
n/aThis feature is not applicable to this regex flavor. Features that describe the behavior of certain syntax introduced earlier in the reference table show n/a for flavors that do not support that syntax at all.
failThe syntax is recognized by the flavor and regular expressions using it work, but this particular regex token always fails to match. The regex can only find matches if this token is made optional by alternation or a quantifier.
2.0–2.9 failVersions 2.0 through 2.9 recognize the syntax, but always fail to match this regex token. Earlier and later versions either don’t recognize the syntax or treat it as a syntax error.
ignoredThe syntax is recognized by the flavor but it does not do anything useful. This particular regex token always finds a zero-length match.
errorThe syntax is recognized by the flavor but it is treated as a syntax error.
Perl regular expression cheat sheet sas

When this legend says “all versions” or “no version”, that means all or none of the versions of each flavor that are covered by the reference tables:

Perl Regular Expression Pdf

JGsoftV1: EditPad 6 and 7; PowerGREP 3 and 4; AceText 3
V2: EditPad 8; PowerGREP 5
.NET1.0–4.8
Java4–14
Perl5.8–5.30
PCRE4.0–8.44
PCRE210.00–10.34
PHP5.0.0–7.4.6
DelphiXE–XE8 & 10–10.4; TRegEx only; also applies to C++Builder XE–XE8 & 10–10.4
R2.14.0–4.0.0
JavaScriptLatest versions of Chrome, Edge, and Firefox
VBScriptVBscript and Internet Explorer in quirks mode
XRegExp2.0.0–4.0.0
Python2.4–3.8
Ruby1.8–2.7
std::regexVisual C++ 2008–2019 (Dinkumware std library)
boost::regex1.38–1.39 & 1.42–1.73
Tcl ARE8.4–8.6
POSIX BREIEEE Std 1003.1
POSIX EREIEEE Std 1003.1
GNU BRE
GNU ERE
Oracle10gR1, 10gR2, 11gR1, 11gR2, 12c
XML1.0–1.1
XPath2.0–3.1

For the .NET flavor, some features are indicated with “ECMA” or “non-ECMA”. That means the feature is only supported when RegexOptions.ECMAScript is set or is not set. Features indicated with “non-ECMA Unicode” match ASCII characters when RegexOptions.ECMAScript is set and Unicode characters when RegexOptions.ECMAScript is not set. Everything that applies to .NET 2.0 or later also applies to any version of .NET Core. The Visual Studio IDE uses the non-ECMA .NET flavor starting with VS 2012.

For the std::regex and boost::regex flavor there are additional indicators ECMA, basic, extended, grep, egrep, and awk. When one or more of these appear, that means that the feature is only supported if you specify one of these grammars when compiling your regular expression. Features with Unicode indicators match Unicode characters when using std::wregex or boost::wregex on wide character strings. In the replacement string reference, the additional indicators are sed and default. When either one appears, the feature is only supported when you either pass or don’t pass match_flag_type::format_sed to regex_replace(). For boost, there is one more replacement indicator “all” that indicates the feature is only supported when you pass match_flag_type::format_all to regex_replace().

For the PCRE2 flavor, some replacement string features are indicated with “extended”. This means the feature is only supported when you pass PCRE2_SUBSTITUTE_EXTENDED to pcre2_substitute.

Perl Compatible Regular Expression Cheat Sheet

Make a Donation

Did this website just save you a trip to the bookstore? Please make a donation to support this site, and you'll get a lifetime of advertisement-free access to this site!

| Quick Start | Tutorial | Tools & Languages | Examples | Reference | Book Reviews |

| Introduction | Table of Contents | Quick Reference | Characters | Basic Features | Character Classes | Shorthands | Anchors | Word Boundaries | Quantifiers | Unicode | Capturing Groups & Backreferences | Named Groups & Backreferences | Special Groups | Mode Modifiers | Recursion & Balancing Groups |

| Characters | Matched Text & Backreferences | Context & Case Conversion | Conditionals |

Regex Cheat Sheet

Page URL: https://regular-expressions.mobi/reference.html
Page last updated: 25 April 2021
Site last updated: 25 April 2021
Copyright © 2003-2021 Jan Goyvaerts. All rights reserved.

Perl Regular Expression Syntax