Regular Expression help...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anand

    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,
  • Eric J. Roode

    #2
    Re: Regular Expression help...

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

    anandnewsgroup@ yahoo.co.uk (Anand) wrote in
    news:f66ae12c.0 307090048.6c75a 114@posting.goo gle.com:
    [color=blue]
    > 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}";[/color]

    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/AwUBPwvq9WPeouI eTNHoEQItDQCeI/yaVs4b6DGT9OoIq k0gBnRPrUoAoOhP
    AS1OnpTX8q7DQ0m PNWHJwpdH
    =WVph
    -----END PGP SIGNATURE-----

    Comment

    Working...