Gossamer Forum
Home : General : Perl Programming :

Regexp : displaying a string

Quote Reply
Regexp : displaying a string
Hi

I have the following string

$string="some textsome textsome textsome text###the text I want to display*** another text another text another text another text";


I just want to display "the text I want to display" (between my special tags ### and ***)

I think it is easy with a regexp

Txs for your help
FMP
Quote Reply
Re: [fmp] Regexp : displaying a string In reply to
You should be able to do something like;

Code:
my $val;
$string =~ m|\#\#\#(.*?)\*\*\*| and $val = $1;

...or possibly;

Code:
my $val;
$string =~ m|\Q###\E(.*?)\Q***| and $val = $1;

$val should then hold the value of whatever is between ### and ***.

hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Regexp : displaying a string In reply to
Or...
Code:
$string =~ /#([^*]+)\*/ && $wanted = $1;

You don't need to escape #'s


Last edited by:

PimpMyRide: Dec 28, 2004, 6:17 PM