Re: Matching of optional parts in regular expressions

From: Ulrich Schöbel (usus_at_aladyn.de)
Date: 07/08/04

  • Next message: zer0frequency: "Java Hashtable performance for contains() method."
    Date: Thu, 8 Jul 2004 18:03:47 +0200
    
    

    In article <40ed1d8f.0407080602.bd6de25@posting.google.com>,
            Markus.Elfring@web.de (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.
    

  • Next message: zer0frequency: "Java Hashtable performance for contains() method."

    Relevant Pages