Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
12
Task/String-matching/Tcl/string-matching-4.tcl
Normal file
12
Task/String-matching/Tcl/string-matching-4.tcl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
set matchLocations [regexp -indices -all -inline ***=$needle $haystack]
|
||||
# Each match location is a pair, being the index into the string where the needle started
|
||||
# to match and the index where the needle finished matching
|
||||
|
||||
set isContained [expr {[llength $matchLocations] > 0}]
|
||||
set isPrefix [expr {[lindex $matchLocations 0 0] == 0}]
|
||||
set isSuffix [expr {[lindex $matchLocations end 1] == [string length $haystack]-1}]
|
||||
set firstMatchStart [lindex $matchLocations 0 0]
|
||||
puts "Found \"$needle\" in \"$haystack\" at $firstMatchStart"
|
||||
foreach location $matchLocations {
|
||||
puts "needle matched at index [lindex $location 0]"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue