Go Back   Velocity Reviews > Newsgroups > PERL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

PERL - Regular Expression help...

 
Thread Tools Search this Thread
Old 07-09-2003, 09:48 AM   #1
Default Regular Expression help...


Given a string with some of the words in curly braces, how do I
extract the words within curly braces alone using regular expression?
Also I wouldnt know how many such words within braces exist in my
string...In such a case how do i extract all the words.

$str = "My {name} is {anand} and i seek {your} help in this
{problem}";

Anand,


Anand
  Reply With Quote
Old 07-09-2003, 11:14 AM   #2
Eric J. Roode
 
Posts: n/a
Default Re: Regular Expression help...

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

(Anand) wrote in
news: om:

> Given a string with some of the words in curly braces, how do I
> extract the words within curly braces alone using regular expression?
> Also I wouldnt know how many such words within braces exist in my
> string...In such a case how do i extract all the words.
>
> $str = "My {name} is {anand} and i seek {your} help in this
> {problem}";


Pretty straightforward:

@words = $str =~ /\{([^}]*)\}/g;

- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPwvq9WPeouIeTNHoEQItDQCeI/yaVs4b6DGT9OoIqk0gBnRPrUoAoOhP
AS1OnpTX8q7DQ0mPNWHJwpdH
=WVph
-----END PGP SIGNATURE-----
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump