$ find("string", 'pattern', [start])

Returns the index of the first substring that matches 'pattern' starting from the specified index.


"string" - the string to search.

'pattern' - a pattern describing the substring to search for.

start - the position from which to begin the search (default is 0)


A scalar integer with the index. A failed search will return $null.


# very naive sentence parser with &find sub parseSentence { $start = 0; while $index (find($1, '(([?!.])\s*)', $start)) { ($match, $type) = matched(); if ($type eq "?") { println("Question: " . substr($1, $start, $index)); } else if ($type eq "!") { println("Excitement: " . substr($1, $start, $index)); } else { println("Boring: " . substr($1, $start, $index)); } $start = $index + strlen($match); } } parseSentence("This is a sentence! And so is this. Questions? Nope.");

Excitement: This is a sentence Boring: And so is this Question: Questions Boring: Nope

See Also