|
Posted by Csaba Gabor on 06/14/06 11:29
Suppose I want to check that a string, $str, starts with at least the
first 3 letters of a given word, say "delete". Can I do that compactly
with a regular expression? The following are not my idea of compact:
preg_match("/^del(|e|et|ete)\\b/i", $str)
Quadratic in the length of the given word
preg_match("/^del(e(t(e)?)?)?\\b/i", $str)
Really now. But at least it's linear
Thanks.
Csaba Gabor from Vienna
Navigation:
[Reply to this message]
|