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
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
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