Overview
| Artifact ID: | f9a133234eafc7402f9cf311d10519de464a25f8 |
|---|---|
| Ticket: | 05beaa6eef4fdb97d6fb518f0508c108c010c548
regexp fails to match braces inside a character class |
| User & Date: | dkf on 2014-02-15 15:08:43 |
Changes
- 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"