Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regex question 3

Status
Not open for further replies.

NEVERSLEEP

Programmer
Apr 14, 2002
667
CA
[ignore]lets say i have this simple regex
"aYEPb" to "bYEPa"
$r =~ s/a(.+?)b/b$1a/gi;
now how can i do
"aYEcNOPEcPb" to "bYEPc"

hope im clear,
thanks for the help[/ignore]

<--
banghead.gif

withstupid.gif
---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
nice that did it :)

<-- very thankfull to both of u
its working, and i learned a few things heh ;) ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
good stuff... Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
I guess you could probably simplify that even further:
Code:
# encode the non-tagged parts
$r =~ s/(.*?)\[notag\](.*?)\[\/notag\](.*)/$1.encode_html($2).$3/egis;

# do the meta-mark-up conversion without converting the non-tagged parts
$r =~ s/\[((?:\/)?(?:b|i|u|a|$othertags))\]/<$1>/gis;

sub encode_html
{
    my ($str) = @_;
    $str =~ s/([^0-9A-Za-z])/sprintf(&quot;&#%d;&quot;,ord($1))/eg;

    return $str;
}
Unless I'm forgetting something, that should work similarly.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
your things works fine thanks again

Code:
$r =~ s/(.*?)\[notag\](.*?)\[\/notag\](.*)/$1.encode_html($2).$3/egis;

just a thing (i though i should post it)
u lose the newlines a simple fix is follow the previous regex with this
Code:
$r =~ s/& # 10 ;/<br>/g;
(no space, of course)

for the curious ;) ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top