Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matching on a string

Status
Not open for further replies.

kirk124

Programmer
Apr 15, 2003
26
US
Hi
I am reading a text file which contain the following string:

my $string = "\\domca-prn01\DH4-2139-HP4"

I need to verify that the string I am reading in has "\\" follow by either characters or numbers then "\" then either characters or numbers.

I try it as:

if ( $string =~ /\\\\.*\\.*/) { print"match\n"; } But it did not work.

thanks in advance.
 
I think that should work if you're reading from a text file, but when you assign it to $string you need to escape the backslashes:

my $string = "\\\\domca-prn01\\DH4-2139-HP4";

hope that helps..

jt
 
Try this:

if ( $string =~ /\\\\\w+\\\w+/) { print"match\n"; }

\\\\ - 2 escaped backslashes

\w+ - then 1 or more "word" charactors (alphanumeric plus some special charactors)

\\ - 1 escaped backslash

\w+ - and again, 1 or more "word" charactors

I highly recommend the book

Mastering Regular Expressions
Powerful Techniques for Perl and Other Tools


By Jeffrey E. F. Friedl

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top