in reply to Re: Problem with Regex
in thread Problem with Regex

I tried (?s:.) instead of .* and still not working, the code has become
sub My_Regex { my($raw_text, $tag) = @_; $raw_text =~ /<$tag>{1}(?s:.)(<\/$tag>){1}/; my $output = $1; print "OUTPUT: $output\n"; }
and still showing nothing

Replies are listed 'Best First'.
Re^3: Problem with Regex
by jethro (Monsignor) on Aug 01, 2011 at 10:30 UTC
     $raw_text =~ /<$tag>{1}(.*)(<\/$tag>){1}/s;

    Try this, the 's' at the end modifies '.' to also match line endings and is guaranteed to work with 5.8.

    By the way, your pattern only works if this tag only occurs once in your string. Otherwise using (.*?) instead of (.*) will at least allow you to find the first occurence. The difference is that .* tries to find the longest possible string while .*? will get the shortest.

Re^3: Problem with Regex
by JavaFan (Canon) on Aug 01, 2011 at 10:24 UTC
    Please follow my instructions. I said to replace the dot with (?s:.), I did not say to replace (.*) with (?s:.).