Regular Expression help...

A

Anand

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,
 
E

Eric J. Roode

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

(e-mail address removed) (Anand) wrote in
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-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top