Regular expressions: Difference between revisions

Content added Content deleted
m (→‎{{header|Tcl}}: formatting)
Line 470: Line 470:


=={{header|Tcl}}==
=={{header|Tcl}}==
Test using <tt>regexp</tt>:

<lang tcl>set theString "I am a string"
Test
if {[regexp -- {string$} $theString]} {

set theString "I am a string"
puts "Ends with 'string'\n"
}
if {[regexp -- {string$} $theString]} {
puts "Ends with 'string'\n"
}
if (![regexp -- {^You} $theString]) {
if {![regexp -- {^You} $theString]} {
puts "Does not start with 'You'\n"
puts "Does not start with 'You'\n"
}</lang>
}


Substitute
Substitute using <tt>regsub</tt>
<lang tcl>set theString = "I am a string"
puts [regsub -- { +a +} $theString { another }]</lang>
set theString = "I am a string"
puts [regsub -- { a } {I am a string} { another }]


=={{header|Toka}}==
=={{header|Toka}}==