Anonymous user
Regular expressions: Difference between revisions
→{{header|Tcl}}: demonstrate substring extraction as well, and apply a bunch of corrections
m (→{{header|AutoHotkey}}: Minor indentation and casing edit) |
(→{{header|Tcl}}: demonstrate substring extraction as well, and apply a bunch of corrections) |
||
Line 488:
=={{header|Tcl}}==
Test using <
<lang tcl>set theString "I am a string"
if {[regexp -- {string$} $theString]} {
puts "Ends with 'string'
}
if {![regexp -- {^You} $theString]} {
puts "Does not start with 'You'
}</lang>
<lang tcl>set theString "This string has >123< a number in it"
if {[regexp -- {>(\d+)<} $theString -> number]} {
puts "Contains the number $number"
}</lang>
Substitute using <code>regsub</code>
<lang tcl>set theString = "I am a string"
puts [regsub -- { +a +} $theString { another }]</lang>
|