Fri, 17 May 2024
NetArt Media     Pay 2, Get 3!    


Perl regular expressions character classes

By: Peter, NetArt Media
Sat, 9 October 2021

\d A digit, same as [0-9]
\D A nondigit, same as [^0-9]
\w A word character (alphanumeric), same as [a-zA-Z_0-9]
\W A nonword character, [^a-zA-Z_0-9]
\s A whitespace character, same as [\t\n\r\f]
\S A non-whitespace character, [^\t\n\r\f]
^ Matches at the beginning of the string (or line, if /m used)
$ Matches at the end of the string (or line, if /m used)
\b Matches at word boundary (between \w and \W)
\B Matches except at word boundary
\A Matches at the beginning of the string
\Z Matches at the end of the string or before a newline
\z Matches only at the end of the string
\G Matches where previous m//g left off

Maximal Minimal Allowed Range
{n,m} {n,m}? Must occur at least n times but no more than m times

{n,} {n,}? Must occur at least n times

{n} {n}? Must match exactly n times

* *? 0 or more times (same as {0,})

+ +? 1 or more times (same as {1,})

? ?? 0 or 1 time (same as {0,1})


Category: Web Development
Share this post:



See All Scripts






Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox