in reply to Problem with Regex

A dot on its own doesn't match a newline. Use /(?s:.)/ instead.

knowing that, I dont use any XML parsers
Maybe you should, otherwise, you'll come back with more questions.

Replies are listed 'Best First'.
Re^2: Problem with Regex
by ŞuRvīvőr (Novice) on Aug 01, 2011 at 10:11 UTC
    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
       $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.

      Please follow my instructions. I said to replace the dot with (?s:.), I did not say to replace (.*) with (?s:.).
Re^2: Problem with Regex
by &#350;uRvīv&#337;r (Novice) on Aug 01, 2011 at 10:03 UTC
    I tried to use an XML parser but I couldn't install it, it needs some C parsers to install and i couldn't do that