Hi

I have problem to get data from tag (eg: <TEXT></TEXT>).

For example the string is like this:

$string = "<TEXT>

Some text

</TEXT>";

if($string =~ /<(TEXT)>\s*(.*)\s*<\/\1>/g)
{
	$result = $2;
	print $result, "\n";
}

It works fine, but if the string is like this:

$string = "<TEXT>
Some text
Another text
</TEXT>";

I got nothing.

Thanks in advance.

things can be that easy.

$string = "<TEXT>
Some text
Another text
</TEXT>";

@s=split /<\/TEXT>/, $string;
$s[0] =~ s/.*<TEXT>// ;
print $s[0];

Hi back2arie,

For what you wrote the regular expression that's all most right.

if($string =~ /<(TEXT)>\s*(.*)\s*<\/\1>/g)

But $string had the text in multiple line. So it's not worked. You will be add 's' modifier in your code, that gives result what you expect.

if($string =~ /<(TEXT)>\s*(.*)\s*<\/\1>/gs)

's' -> Treat string as single line.

This question has already been answered. Start a new discussion instead.