Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Probs with regex and nesting

Reply
Thread Tools

Probs with regex and nesting

 
 
Gyruss
Guest
Posts: n/a
 
      08-14-2005
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";
}
}


 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      08-14-2005
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
 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      08-14-2005


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).

/^{[^{]*}$/

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex testing and UTF8 awarenes or Regex and numeric pattern matching sln@netherlands.com Perl Misc 2 03-10-2009 03:51 AM
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
String Pattern Matching: regex and Python regex documentation Xah Lee Java 1 09-22-2006 07:11 PM
ATI Graphics probs, DVICO FUSION DUAL DGITAL probs, and X64 =?Utf-8?B?Tmljaw==?= Windows 64bit 0 01-09-2006 04:29 AM
Module.nesting -> Kernel#nesting Trans Ruby 10 09-16-2005 12:21 AM



Advertisments