Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Matching of optional parts in regular expressions

Reply
Thread Tools

Re: Matching of optional parts in regular expressions

 
 
Markus Elfring
Guest
Posts: n/a
 
      07-08-2004
Does this example show an error in the implementation?

% regexp {\s*(\d+)(?:%(\w+))?} { !123!} z a b
1
% foreach X {a b} {puts "$X=|[set $X]|"}
a=|123|
b=||
% regexp {\s*(\d+)(?:%(\w+))?$} { !123!} z a b
0
% regexp {\s*(\d+)(?:%(\w+))?} { 456%} z a b
1
% foreach X {a b} {puts "$X=|[set $X]|"}
a=|456|
b=||

I think that the specified strings must not match to the pattern.
How do you think about it?
 
Reply With Quote
 
 
 
 
Ulrich Schöbel
Guest
Posts: n/a
 
      07-08-2004
In article <(E-Mail Removed)> ,
http://www.velocityreviews.com/forums/(E-Mail Removed) (Markus Elfring) writes:
> Does this example show an error in the implementation?


No. All three examples work absolutely correct.

>
> % regexp {\s*(\d+)(?:%(\w+))?} { !123!} z a b
> 1
> % foreach X {a b} {puts "$X=|[set $X]|"}
> a=|123|
> b=||


Regex is not anchored. It matches no whitespace (\s*),
three digits (\d+) and no word introduced by a % sign.

> % regexp {\s*(\d+)(?:%(\w+))?$} { !123!} z a b
> 0


Same as before, but anchored at the end. The final ! is
not matched, so the entire regex doesn't match.

> % regexp {\s*(\d+)(?:%(\w+))?} { 456%} z a b
> 1
> % foreach X {a b} {puts "$X=|[set $X]|"}
> a=|456|
> b=||


Same as first example.

>
> I think that the specified strings must not match to the pattern.
> How do you think about it?


Everything is working ok.

Best regards

Ulrich


--
For those of you who don't get this e-mail, let me know and I'll re-send it.
 
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
Re: [Tutor] matching a street address with regular expressions Shawn Milochik Python 15 10-12-2007 11:50 PM
Regular expressions - matching strings sconeek@gmail.com Java 2 04-04-2006 02:48 PM
Parts parts....PARTS!!! ARGHHH dstvns A+ Certification 8 01-07-2004 07:57 PM
matching curly braces and regular expressions Dustin D. Perl 0 08-26-2003 11:18 PM
Add custom regular expressions to the validation list of available expressions Jay Douglas ASP .Net 0 08-15-2003 10:19 PM



Advertisments