Re: regexp to match any initial substring of a string?

On Sep 16, 11:00 am, Alexander Rast <alex.rast.techni...@xxxxxxxxx>
This is either going to be easy, or impossible; I can't determine

I want to search for words that form any legitimate leading substring
of a long potential string.

So let's say I had the string supercalifragilisticexpialidocious as a
match target, I want to match any word in the set {s su sup supe ...
supercalifragilisticexpialidociou supercalifragilisticexpialidocious}
occurring in the search string. (The search should use greedy matching
so as to suck up as much of the target as it can find)

It doesn't take much thought to realise how tedious this could become
using regexp if you have to define a separate branch for each
possibility. The problem is especially onerous if (such as I have) you
have several such long strings each of which should be tested

Is there a regexp for this?

No need for regular expressions. Keep it simple:

set target supercalifragilisticexpialidocious
set test supe

if {[string range $target 0 [string length $test]-1] eq $test} {
puts "$test is a prefix of $word"