Skip to content
Tcl Source Code History Of Ticket 05beaa6ee
Login

History Of Ticket 05beaa6ee

Artifacts Associated With Ticket 05beaa6ee

  1. Ticket change [35bdf39248] (rid 136888) by ericp on 2014-02-15 01:54:00:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/html"
    4. comment initialized to:
      <p>I want to match a set of characters including letters,
      spaces, brackets and braces between two words:
      
      <pre>
      % set ptn {the ([\w\{\}\[\]\s]+) test}
      the ([\w\{\}\[\]\s]+) test
      
      # Words and spaces match
      % regexp -inline $ptn {the abc def test}
      {the abc def test} {abc def}
      
      # Words and square brackets match
      % regexp -inline $ptn {the abc][def test}
      {the abc][def test} {abc][def}
      
      # Even a single square bracket will match
      % regexp -inline $ptn {the [ test}
      {the [ test} {[}
      
      # But tcl fails to match braces:
      % regexp -inline $ptn {the abc\}\{def test}
      % regexp -inline $ptn {the abc\{def test}
      % regexp -inline $ptn {the \{ test}
      </pre>
      
    5. foundin initialized to: "8.6"
    6. is_private initialized to: "0"
    7. login: "ericp"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "6d1053e9208f1074fd485c15cc0d7e49e190bac5"
    10. resolution initialized to: "None"
    11. severity initialized to: "Important"
    12. status initialized to: "Open"
    13. submitter initialized to: "ericp"
    14. subsystem initialized to: "43. Regexp"
    15. title initialized to:
      regexp fails to match braces inside a character class
      
    16. type initialized to: "Bug"
  2. Ticket change [c4498e7806] (rid 136889) by ericp on 2014-02-15 01:55:38:

    1. icomment: "http://bugs.activestate.com/show_bug.cgi?id=102789"
    2. login: "ericp"
    3. mimetype: "text/plain"
    4. username: "Ref Komodo bug"
  3. Ticket change [27b2bfcefe] (rid 136890) by ericp on 2014-02-15 02:15:56:

    1. closedate changed to: "2456703.59439865"
    2. closer changed to: "ericp"
    3. icomment:
      I figured out that I have to triple-escape the braces in the character class.
      
    4. login: "ericp"
    5. mimetype: "text/plain"
    6. resolution changed to: "Invalid"
    7. status changed to: "Closed"
  4. Ticket change [f9a133234e] (rid 136893) by dkf on 2014-02-15 15:08:43:

    1. closedate changed to: "2456704.13106343"
    2. closer changed to: "dkf"
    3. icomment:
      I'm confused by what you thought you were matching. In particular, I suspect that the string you were <i>matching against</i> was not what you thought it was. Also, it's really best to put the close square bracket at the start of a match set, and you don't need nearly so many backslashes.
      <pre>
      % set ptn {the ([][{}\w\s]+) test}
      the ([][{}\w\s]+) test
      % regexp -inline $ptn {the abc def test}
      {the abc def test} {abc def}
      % regexp -inline $ptn {the abc][def test}
      {the abc][def test} {abc][def}
      % regexp -inline $ptn {the [ test}
      {the [ test} {[}
      </pre>
      What were you meaning to have as the strings you matched against?
      <pre>
      % regexp -inline $ptn {the abc\}\{def test}
      % regexp -inline $ptn "the abc\}\{def test"
      the\ abc\}\{def\ test abc\}\{def
      % # That looks confusing; once more, with list extraction!
      % foreach bit [regexp -inline $ptn "the abc\}\{def test"] {puts [incr i]=>$bit}
      1=>the abc}{def test
      2=>abc}{def
      % puts {the abc\}\{def test}
      the abc\}\{def test
      % puts "the abc\}\{def test"
      the abc}{def test
      </pre>
      That is, were you intending to have a literal backslash in the match set? In case you were, here's a working, minimal version. (Braces aren't special to RE character sets <i>per se</i> but they can interact with how you're quoting the string.)
      <pre>
      % <b>### NOTE THE EXTRA PAIR OF BACKSLASHES; ONLY DIFFERENCE! ###</b>
      % set ptn {the ([][{}\w\s\\]+) test}
      the ([][{}\w\s\\]+) test
      % regexp -inline $ptn {the abc\}\{def test}
      {the abc\}\{def test} {abc\}\{def}
      </pre>
      Some general comments. Embedded unbalanced braces break brace-quoting of literals. Always have (since one of the very earliest versions). This isn't much of an issue normally as they're pretty rare except in test data. The list-quoting engine copes by switching to a different quoting style, as you might guess from the output traces above.
      
    4. login: "dkf"
    5. mimetype: "text/html"
    6. username: "dkf"