in reply to Re: Match problem
in thread Regex problem

I modified the code in my original post a little bit adding he suggestions made by you.

I see part of my output getting printed,i.e.,"//perl/tools/files/modem +/rrc/main/latest/src/rrcrbcommon.c" is getting printed but why is "// +perl/tools/files/data/HFAT_01_01/src/VU_CORE_STORAGE_HFAT.01.01.35.tx +t#1" still not getting printed?path after the word "branch from" has +to be printed.

Replies are listed 'Best First'.
Re^3: Match problem
by perl_mystery (Beadle) on Dec 22, 2010 at 01:42 UTC

    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?

      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