What's the difference in this "string match"ing ... - TCL

This is a discussion on What's the difference in this "string match"ing ... - TCL ; Hello, I traced down a problem I can not understand. Why is the following different? (perhabs the question is foolish or the answer is the easiest to find, but ...) % string match {*\\} "a\\" 1 % string match "*\\" ...

+ Reply to Thread
Results 1 to 3 of 3

What's the difference in this "string match"ing ...

  1. Default What's the difference in this "string match"ing ...

    Hello,

    I traced down a problem I can not understand.

    Why is the following different? (perhabs the question is foolish or
    the answer is the easiest to find, but ...)

    % string match {*\\} "a\\"
    1
    % string match "*\\" "a\\"
    0

    Thanks for any hint!

    Martin Lemburg
    Siemens Automation and Drives - UGS PLM Software


  2. Default Re: What's the difference in this "string match"ing ...


    MartinLemburg{}UGS schrieb:
    > Hello,
    >
    > I traced down a problem I can not understand.
    >
    > Why is the following different? (perhabs the question is foolish or
    > the answer is the easiest to find, but ...)
    >
    > % string match {*\\} "a\\"
    > 1
    > % string match "*\\" "a\\"
    > 0
    >
    > Thanks for any hint!


    The man page for string match states:
    \x
    Matches the single character x. This provides a way of avoiding the
    special interpretation of the characters *?[]\ in pattern.

    In your first example, string match substitutes the \\ with a single
    \, in the second example it is already substituted by the parser and
    string match gets a single \, which it interprets strangely.

    Michael


  3. Default Re: What's the difference in this "string match"ing ...

    MartinLemburg{}UGS wrote:
    > Hello,
    >
    > I traced down a problem I can not understand.
    >
    > Why is the following different? (perhabs the question is foolish or
    > the answer is the easiest to find, but ...)
    >
    > % string match {*\\} "a\\"
    > 1
    > % string match "*\\" "a\\"
    > 0
    >
    > Thanks for any hint!
    >


    here's a hint

    set a {*\\}
    set b "*\\"

    puts "length of a = [string length $a]"
    puts "length of b = [string length $b]"

    puts "a contains <$a>"
    puts "b contains <$b>"


    Bruce

+ Reply to Thread

Similar Threads

  1. Replies: 1
    Last Post: 05-16-2007, 01:50 PM
  2. Replies: 2
    Last Post: 03-21-2007, 02:36 AM
  3. problem about xpath match string with "/"
    By Application Development in forum XML SOAP
    Replies: 1
    Last Post: 06-15-2006, 10:22 AM
  4. Replies: 5
    Last Post: 11-17-2005, 04:54 PM