kirk123 has asked for the wisdom of the Perl Monks concerning the following question:

Hi I am reading a text file which contain the following 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 this as: if ( $string =~ /\\\\.*\\.*/) { print"match\n"; } But it did not work. thanks in advance.

Replies are listed 'Best First'.
Re: Matching on a string
by diotalevi (Canon) on Jul 15, 2003 at 22:52 UTC

    Easy enough: if ( $string =~ /\\\\[^\\]+\\[^\\]/) { print "match\n"; }. This says to have two backslashes, one or more things that aren't backslashes, another backslash and then something that isn't a backslash. You may want to check out death to dot star.

Re: Matching on a string
by the pusher robot (Monk) on Jul 15, 2003 at 22:55 UTC

    The following works for me:

    my $string = '\\\\domca-prn01\DH4-2139-HP4'; if ( $string =~ /\\\\.*\\.*/) { print"match\n"; }

    Note that I had to double the backslashes in the string, because the first one was escaping the second. You also probably want to use a character class (e.g., [\w-]+) or at least [^\\]+ instead of .*.