in reply to Re^2: Match problem
in thread Regex problem

I noticed the following probs

1.Whenever there is an underscore "_" in the input the regex is failing

2.Also after taking care of first step,meaning removing underscores and them removing the line after "branch from" ,i.e.,... ... branch into //perl/tools/files/data/HFAT_01_01/src/VU_CORE_STORAGE_HFAT.01.01.37.txt#1",the regex matches.

Can the monks provide input on how to change the regex to match the above two scenarios?Is there a way I can just get the "branch from" line and perform my regex on that line?

Replies are listed 'Best First'.
Re^4: Match problem
by oko1 (Deacon) on Dec 22, 2010 at 02:49 UTC

    Whenever there is an underscore "_" in the input the regex is failing

    The problem here seems to be that you're taking wild guesses at how things should work rather than reading, understanding, and following the documentation. E.g., $1 will not appear out of thin air and be magically populated with the thing you were thinking about. Underscores in the input will rarely make a regex fail, but a regex that is not correctly written for the thing you want to match will not match that thing.

    I suggest carefully and attentively reading perlretut, coding and trying the example patterns that are shown in it. Once you understand those, you'll be able to construct the regex that you want.

    # Example for a similar case my @lines = ( "valid path /export/home/joe/data/01/", "ignore this one /var/apache/htdocs/", "valid path /usr/local/share/foobar/", "just testing /var/log/secure", "valid path /export/home/susan/recipes/" ); for (@lines){ if (m[^valid path\s+(/.*/)]){ print "$1\n"; } }

    Output:

    /export/home/joe/data/01/ /usr/local/share/foobar/ /export/home/susan/recipes/

    --
    "Language shapes the way we think, and determines what we can think about."
    -- B. L. Whorf