Regular expression problem: "|" interferring with ".*?" 
Author Message
 Regular expression problem: "|" interferring with ".*?"

In tclsh8.3:
    % set a "012012012012"
    012012012012
    % regexp -inline "0.*?2" $a
    012
    % regexp -inline "0.*?2|x" $a
    012012012012

Why adding a branch to the pattern makes "*?" greedy?
--
= Q. Alex Zhao
  http://www.*-*-*.com/ ~qiang.a.zhao/

  Graphics, Visualization & Usability Center, Georgia Inst. of Tech.



Mon, 19 Aug 2002 03:00:00 GMT  
 Regular expression problem: "|" interferring with ".*?"

Quote:

> In tclsh8.3:
>     % set a "012012012012"
>     012012012012
>     % regexp -inline "0.*?2" $a
>     012
>     % regexp -inline "0.*?2|x" $a
>     012012012012

> Why adding a branch to the pattern makes "*?" greedy?

I've passed this onto Henry Spencer for clarification (this is
new for the 8.1+ regexp).  As a work-around you can use:

(tkcon) 60 % regexp -inline {0[^2]*2|x} $a
012
(tkcon) 61 % regexp -inline {0[^2]*2} $a
012

--
   Jeffrey Hobbs                          The Tcl Guy
   jeffrey.hobbs at scriptics.com         Scriptics Corp.



Mon, 19 Aug 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

2. "Regular Expression?"

3. Regular Expression Pattern Matching "State" Object

4. Replace with regular expressions "except if..."

5. "Invert" regular expression matching

6. BEGIN{want[]={"s1o", "s2o", "s2q", "s3q"}

7. Parsing ""D""?

8. "Fifth", "Forth", zai nar?

9. Ruby "finalize", "__del__"

10. beginners "let"/"random" question

11. ANNOUNCE: new "plus"- and "dash"-patches available for Tcl7.5a2/Tk4.1a2

12. Looking for "stdin", "stdout"

 

 
Powered by phpBB® Forum Software