Probs with regex and nesting

Discussion in 'Perl Misc' started by Gyruss, Aug 14, 2005.

  1. Gyruss

    Gyruss Guest

    Hi,

    I'm having trouble modifying the regular expression /^\{.*\}$/ so that a
    string with nested curly braces is deemed unmatched. E.g

    {recognizing syntax} - matched
    {recognizing syntax {foo} bar} - unmatched.
    {recognizing syntax {foo{ foo bar}} {bar}} - unmatched.

    Can this be done?

    Cheers!

    use warnings;
    use strict;

    while (<>) {
    chomp;
    if (/^\{.*\}$/) {
    print "Matched: |$`<$&>$'|\n";
    } else {
    print "No match.\n";
    }
    }
     
    Gyruss, Aug 14, 2005
    #1
    1. Advertising

  2. Gyruss wrote:
    > I'm having trouble modifying the regular expression /^\{.*\}$/ so that a
    > string with nested curly braces is deemed unmatched. E.g
    >
    > {recognizing syntax} - matched
    > {recognizing syntax {foo} bar} - unmatched.
    > {recognizing syntax {foo{ foo bar}} {bar}} - unmatched.


    /^{[^{}]*}$/

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Aug 14, 2005
    #2
    1. Advertising

  3. Gyruss wrote:
    > Hi,
    >
    > I'm having trouble modifying the regular expression /^\{.*\}$/ so that a
    > string with nested curly braces is deemed unmatched. E.g
    >
    > {recognizing syntax} - matched
    > {recognizing syntax {foo} bar} - unmatched.
    > {recognizing syntax {foo{ foo bar}} {bar}} - unmatched.
    >
    > Can this be done?


    Can your criteria be expressed as "a string containing another '{'
    character is unmatched?" (If not how are your criteria different).

    /^{[^{]*}$/
     
    Brian McCauley, Aug 14, 2005
    #3
    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. Atul

    Gnutella lite + mfc70.dll probs

    Atul, Nov 23, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    1,343
  2. Carl Howarth

    Deployment Performance Probs

    Carl Howarth, Aug 6, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    294
    Carl Howarth
    Aug 6, 2003
  3. Mukesh
    Replies:
    3
    Views:
    566
    Steven Cheng[MSFT]
    Jul 10, 2007
  4. Replies:
    3
    Views:
    809
    Reedick, Andrew
    Jul 1, 2008
  5. Trans
    Replies:
    10
    Views:
    319
    Sean O'Halpin
    Sep 16, 2005
Loading...

Share This Page