<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.scott5.org/index.php?action=history&amp;feed=atom&amp;title=Perl_Regular_Expressions</id>
	<title>Perl Regular Expressions - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.scott5.org/index.php?action=history&amp;feed=atom&amp;title=Perl_Regular_Expressions"/>
	<link rel="alternate" type="text/html" href="https://wiki.scott5.org/index.php?title=Perl_Regular_Expressions&amp;action=history"/>
	<updated>2026-04-13T00:32:22Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://wiki.scott5.org/index.php?title=Perl_Regular_Expressions&amp;diff=203&amp;oldid=prev</id>
		<title>Scott: Created page with &#039;== Perl Regular Expressions == &lt;source lang=&quot;perl&quot;&gt; /a.c/        # (1 of any character) matches &quot;abc&quot; but not &quot;ac&quot; or &quot;abbc&quot; /a*c/        # (0 or more) matches &quot;c&quot;, &quot;ac&quot;, &quot;aac&quot;, …&#039;</title>
		<link rel="alternate" type="text/html" href="https://wiki.scott5.org/index.php?title=Perl_Regular_Expressions&amp;diff=203&amp;oldid=prev"/>
		<updated>2011-02-01T18:27:01Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039;== Perl Regular Expressions == &amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt; /a.c/        # (1 of any character) matches &amp;quot;abc&amp;quot; but not &amp;quot;ac&amp;quot; or &amp;quot;abbc&amp;quot; /a*c/        # (0 or more) matches &amp;quot;c&amp;quot;, &amp;quot;ac&amp;quot;, &amp;quot;aac&amp;quot;, …&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Perl Regular Expressions ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
/a.c/        # (1 of any character) matches &amp;quot;abc&amp;quot; but not &amp;quot;ac&amp;quot; or &amp;quot;abbc&amp;quot;&lt;br /&gt;
/a*c/        # (0 or more) matches &amp;quot;c&amp;quot;, &amp;quot;ac&amp;quot;, &amp;quot;aac&amp;quot;, &amp;quot;aaac&amp;quot;, but not &amp;quot;abc&amp;quot;&lt;br /&gt;
/a+c/        # (1 or more) matches &amp;quot;ac&amp;quot;, &amp;quot;aac&amp;quot;, &amp;quot;aaac&amp;quot;, but not &amp;quot;abc&amp;quot; or &amp;quot;c&amp;quot;&lt;br /&gt;
/a?c/        # (0 or 1) matches &amp;quot;c&amp;quot; and &amp;quot;ac&amp;quot; but not &amp;quot;aac&amp;quot;, &amp;quot;aaac&amp;quot; or &amp;quot;abc&amp;quot;&lt;br /&gt;
/a{2,3}c/    # (2 to 3) matches &amp;quot;aac&amp;quot; and &amp;quot;aaac&amp;quot; but not &amp;quot;ac&amp;quot;&lt;br /&gt;
/a{2,}c/     # (2 or more) matches &amp;quot;aac&amp;quot; and &amp;quot;aaaaaac&amp;quot; but not &amp;quot;ac&amp;quot;&lt;br /&gt;
/a{2}c/      # (2) matches &amp;quot;aac&amp;quot;&lt;br /&gt;
/a(bc)?d/    # matches &amp;quot;ad&amp;quot; and &amp;quot;abcd&amp;quot;&lt;br /&gt;
/a(bb|cc)d/  # matches &amp;quot;abbd&amp;quot; and &amp;quot;accd&amp;quot;&lt;br /&gt;
/a[bc]d/     # matches &amp;quot;abd&amp;quot; and &amp;quot;acd&amp;quot;&lt;br /&gt;
/a[0-9]+c/   # matches &amp;quot;a123c&amp;quot; but not &amp;quot;ac&amp;quot; or &amp;quot;a1b2c&amp;quot;&lt;br /&gt;
/a[^0-9]c/   # matches &amp;quot;abc&amp;quot; but not &amp;quot;ac&amp;quot; or &amp;quot;a1c&amp;quot;&lt;br /&gt;
\d matches a digit [0-9]&lt;br /&gt;
\w matches a word character [A-Za-z0-9_]&lt;br /&gt;
\s matches a whitespace character [\f\t\n\r ]&lt;br /&gt;
\D = [^\d], \W = [^\w], \S = [^\s]&lt;br /&gt;
/[\dA-Fa-f]+/  # matches hexadecimal numbers&lt;br /&gt;
m([\dA-Fa-f]+) # same, can enclose with arbitrary punctuation pairs&lt;br /&gt;
m{http://}     # matches &amp;quot;http://&amp;quot;&lt;br /&gt;
/yes/i         # (case insensitive) matches &amp;quot;yes&amp;quot;, &amp;quot;Yes&amp;quot;, and &amp;quot;YES&amp;quot;&lt;br /&gt;
/^&amp;gt;/           # match &amp;quot;&amp;gt;&amp;quot; character at beginning of line&lt;br /&gt;
/&amp;gt;$/           # match &amp;quot;&amp;gt;&amp;quot; character at end of line&lt;br /&gt;
/^abc$/        # only matches &amp;quot;abc&amp;quot;&lt;br /&gt;
/^\s*$/        # matches any line containing only whitespace&lt;br /&gt;
/\babc\b/      # (word boundary) matches &amp;quot;my abc&amp;quot; but not &amp;quot;abcd&amp;quot;&lt;br /&gt;
# (...) saves regular expression submatches to memory&lt;br /&gt;
$_ = &amp;quot;Hello there, neighbor&amp;quot;;&lt;br /&gt;
if (/(\S+) (\S+), (\S+)/) {&lt;br /&gt;
  print &amp;quot;words were $1 $2 $3\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
# automatic match variables&lt;br /&gt;
# $` is everything before the match&lt;br /&gt;
# $&amp;amp; is the match itself&lt;br /&gt;
# $&amp;#039; is everthing after the match&lt;br /&gt;
if (&amp;quot;Hello there, neighbor&amp;quot; =~ /\s(\w+),/) {&lt;br /&gt;
  print &amp;quot;words were $` $&amp;amp; $&amp;#039;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
my $string = &amp;quot;Here is my string.&amp;quot;;&lt;br /&gt;
if ($string =~ /[Hh]ere/){...}  # matches&lt;br /&gt;
# translate lowercase vowels to upper&lt;br /&gt;
$string =~ tr/aeiou/AEIOU/;   # HErE Is my strIng.&lt;br /&gt;
# delete all whitespace (g means global)&lt;br /&gt;
$string =~ s/\s+//g;          # HErEIsmystrIng.&lt;br /&gt;
if ($string =~ /[aeiou]/) {&lt;br /&gt;
    print &amp;quot;Found lowercase vowels.&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
# may use non-slash delimiters&lt;br /&gt;
s{^https://}{http://}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== A Program for Testing Regular Expressions ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/perl&lt;br /&gt;
while (&amp;lt;&amp;gt;) {                   # take one input line at a time&lt;br /&gt;
  chomp;&lt;br /&gt;
  if (/YOUR_PATTERN_GOES_HERE/) {&lt;br /&gt;
    print &amp;quot;Matched: |$`&amp;lt;$&amp;amp;&amp;gt;$&amp;#039;|\n&amp;quot;;  # the special match vars&lt;br /&gt;
  } else {&lt;br /&gt;
    print &amp;quot;No match: |$_|\n&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Uses for Regular Expressions ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
@fields = split /:/, &amp;quot;abc:def:g:h&amp;quot;;    # gives (&amp;quot;abc&amp;quot;, &amp;quot;def&amp;quot;, &amp;quot;g&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
@fields = split /\s+/, &amp;quot;I am a cow.&amp;quot;;  # gives (&amp;quot;I&amp;quot;, &amp;quot;am&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;cow.&amp;quot;)&lt;br /&gt;
@fields = split &amp;#039; &amp;#039;, &amp;quot;I am a cow.&amp;quot;;    # gives (&amp;quot;I&amp;quot;, &amp;quot;am&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;cow.&amp;quot;)&lt;br /&gt;
my $sentence = join &amp;#039;_&amp;#039;, @fields;      # gives &amp;quot;I_am_a_cow.&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Scott</name></author>
	</entry>
</feed>