Perlfect Solutions
 

Perl Regex Tutorial

The Perl Regex Tutor shows you what a pattern will match against a string you provide. Start by entering a regex and some input in the boxes below and clicking the run button.
Regex:
Input:
Case-insensitive

Result

The matching part of the input appears in bold. Spaces are shown as ⋅. Capture groups are highlighted.

R e g e x T u t o r

Capture groups

You may turn capture groups on and off by clicking on the colored boxes.

Reg
T

Digg! Save This Page

Comments

Carlos   

Posted at 7:27am on Monday, August 27th, 2007

Very usefull

Carlos   

Posted at 7:31am on Monday, August 27th, 2007

Why this regex "^-\(w+)" does not retreive enything from here "-lolo",

Thank you very much

Perlfect   

Posted at 7:35am on Monday, August 27th, 2007

Carlos, the backslash should be before the "w+", not the parenthesis. Your regex should read "^-(\w+)", without the quotes.

Eddie   

Posted at 12:51pm on Tuesday, September 11th, 2007

I put (/w+) in your tutorial running on \fredupperlower/clipped/file.txt and it matches /clipped, which I want it to. But in my script, it's not working. The sequence is:

$dir = $File::Find::dir;
$dir =~ /(/w+)/;
$dirname = $1;
print "directory name: $dirnamen";

Eddie   

Posted at 1:16pm on Tuesday, September 11th, 2007

I tried using:

$dir =~ m!/(w+)!;

and that seemed to work (better than I expected, since it returns "clipped" instead of "/clipped" which is easier to work with for my purposes).

Agus   

Posted at 10:19am on Thursday, September 13th, 2007

I need your, how to validate phone number. eg: (021)087655 or 021-56745.

thanks

Sleve   

Posted at 6:53pm on Monday, September 24th, 2007

Agus: (d{3})d{6} or
d{3}-d{5}
I forget how to make it so that "either" will grab the line.
(((d{3})d{6})|(d{3}-d{5})) should have done it, I think, but it failed to catch the second one in capture groups.

Sleve   

Posted at 6:56pm on Monday, September 24th, 2007

Agus: I put it in correctly, but the comment engine stripped out some back slashes. There should be a backslash before each parenthesis in the first one listed.

Kokok   

Posted at 12:30am on Thursday, January 10th, 2008

This page is great to test my regex

Comments to date: 9.

Your name:
Your comments:

Security check *

 

Like it? Share it!

  Post to del.icio.us
Post to
del.icio.us