Artifacts Associated With Ticket 05beaa6ee
Ticket change [35bdf39248] (rid 136888) by ericp on 2014-02-15 01:54:00:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/html"
- 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> - foundin initialized to: "8.6"
- is_private initialized to: "0"
- login: "ericp"
- priority initialized to: "5 Medium"
- private_contact initialized to: "6d1053e9208f1074fd485c15cc0d7e49e190bac5"
- resolution initialized to: "None"
- severity initialized to: "Important"
- status initialized to: "Open"
- submitter initialized to: "ericp"
- subsystem initialized to: "43. Regexp"
- title initialized to:
regexp fails to match braces inside a character class
- type initialized to: "Bug"
Ticket change [c4498e7806] (rid 136889) by ericp on 2014-02-15 01:55:38:
- icomment: "http://bugs.activestate.com/show_bug.cgi?id=102789"
- login: "ericp"
- mimetype: "text/plain"
- username: "Ref Komodo bug"
Ticket change [27b2bfcefe] (rid 136890) by ericp on 2014-02-15 02:15:56:
- closedate changed to: "2456703.59439865"
- closer changed to: "ericp"
- icomment:
I figured out that I have to triple-escape the braces in the character class.
- login: "ericp"
- mimetype: "text/plain"
- resolution changed to: "Invalid"
- status changed to: "Closed"
Ticket change [f9a133234e] (rid 136893) by dkf on 2014-02-15 15:08:43:
- closedate changed to: "2456704.13106343"
- closer changed to: "dkf"
- 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. - login: "dkf"
- mimetype: "text/html"
- username: "dkf"