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];

Thanks, it's works :)

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.