Home: Perl Programming Help: Regular Expressions:
Regex failing



Jeff29
Novice

Dec 17, 2010, 2:39 PM


Views: 5709
Regex failing

INPUT:-
//tools/scripts/script_rev1.1.txt
//tools/scripts/files_data.txt

My below regeex fails when there is a "." (dot) in the PLF,how do I change it to match both the above examples?

Code
($line =~ /\/(\w+\.txt)/)



(This post was edited by Jeff29 on Dec 17, 2010, 2:39 PM)


Zhris
Enthusiast

Dec 17, 2010, 4:08 PM


Views: 5705
Re: [Jeff29] Regex failing

Use a character class instead, and include the ".". Probably a good idea to place an $ anchor on the end of the expression too.


Code
print "$1\n" if ($line =~ /\/([\w\.]+\.txt)$/);


Chris


(This post was edited by Zhris on Dec 17, 2010, 4:11 PM)