Regular Expression help...

Discussion in 'Perl' started by Anand, Jul 9, 2003.

  1. Anand

    Anand Guest

    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, Jul 9, 2003
    #1
    1. Advertising

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

    (Anand) wrote in
    news::

    > 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-----
     
    Eric J. Roode, Jul 9, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric B.
    Replies:
    1
    Views:
    437
    Jim Gibson
    Dec 17, 2004
  2. Jorell

    Regular Expression Help

    Jorell, Jul 28, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    482
    William F. Robertson, Jr.
    Jul 29, 2003
  3. VSK
    Replies:
    2
    Views:
    2,355
  4. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    873
    Alan Moore
    Dec 2, 2005
  5. GIMME
    Replies:
    3
    Views:
    12,025
    vforvikash
    Dec 29, 2008
Loading...

Share This Page