Hello,

my $Data = "Hello, i am a litte String.$ Please format me.$$$ I am the end
of the String.$$ And i am the last!"

The regex should replace $ with the string <br>, $$ with <p> and $$$ with
<br><br> (please don't think about the why)

If tried to use the following:
$data =~ s/\$\$\$/<br><br>/gm; #should catch every occurrence of $$$
$data =~ s/\$\$/<p>/gm; #should catch $$
$data =~ s/\$/<br>/gm; #the rest

So data should look after the first regex:
Hello, i am a litte String.$Please format me.<br><br>I am the end of the
String.$$And i am the last!
And after the second:
Hello, i am a litte String.$Please format me.<br><br>I am the end of the
String.<p>And i am the last!
And the last:
Hello, i am a litte String.<br>Please format me.<br><br>I am the end of the
String.<p>And i am the last!

But all regexes i tried (the one above are only one try) failed! When i
print out the string it looks like:

Hello, i am a litte String. Please format me. I am the end of the
String.3398 And i am the last!

Where the number after String. differs between every run.

Can someone help me ?

This works at least on my machine:

use strict;
use warnings;

my $Data = 'Hello, i am a litte String.$ Please format me.$$$ I am the end of the String.$$ And i am the last!';

$Data =~ s/([^\$]*)\${3,3}([^\$]+)/$1\<br\>\<br\>$2/gm;
$Data =~ s/([^\$]*)\${2,2}([^\$]+)/$1\<p\>$2/gm;
$Data =~ s/([^\$]*)\${1,1}([^\$]+)/$1\<br\>$2/gm;
print "Data: $Data \n";

___END___

Notice, I change the double quotes to single quotes for $Data.
For me, the regex is clear. But if not for you, I can explain.
There are maybe some "better" solution, this is just a quick one.

Regards
Karl-Heinz


_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to