Match Literal Text

1. Subject

Characters in the ASCII table are: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~


2. Match 

Characters in the ASCII table are: !"#\$%&'\(\)\*\+,-\./:;<=>\?@\[\\]\^_`\{\|}~


3. Application or Code

1)  Test is the regex matches a string

set result [regexp -linestop {Characters in the ASCII table are: !"#\$%&'\(\)\*\+,-\./:;<=>\?@\[\\\]\^_`\{\|\}~} $subject]

2)  Get the part of a string matched by the regex

regexp -linestop {Characters in the ASCII table are: !"#\$%&'\(\)\*\+,-\./:;<=>\?@\[\\\]\^_`\{\|\}~} $subject result

3) Iterate over all matches in a string

set pos 0
while {[regexp -indices -start $pos -linestop {Characters in the ASCII table are: !"#\$%&'\(\)\*\+,-\./:;<=>\?@\[\\\]\^_`\{\|\}~} $subject offsets]==1} {
  set pos [expr {1+[lindex $offsets 1]}]
  lappend result [string range $subject [lindex $offsets 0] [lindex $offsets 1]]
}

你可能感兴趣的:(编程语言)