hi, 
can anyone help me with the following problem.
i've designed a search engine, and would like to finish implementing highlighting of the search match results in another colour.
with a regex:
eg:
$teststr = "transferase protein is a ras molecule";
$thestr = "\bras\b";
if ($teststr =~ /($thestr)/) {
$matched = $1;
$wherematched = index($teststr, $matched);
}
in this case, i want the regex to match the word "ras" alone (not the unbound 'ras' in "transfeRASe"
. This i have working.
however, to do the highlighting of the match result in the HTML output, i need to find out the position of the match made by regex.
the index function above does not go by the regex match position, but instead matches to the first occurrence of $1 ($1 = 'ras') and thus instead matches with "transferase" and gives an index of 7 (i want to get 25). Is there any way to 'link' the regex results with the index function?
I'm aware the index function allows to "skip" to the next match, but this is not what i want because in my case the match position is often variable (i.e. there may be other 'ras' mismatches before the real one that regex properly catches).
can anyone help?
THANKS!!!
Ben
can anyone help me with the following problem.
i've designed a search engine, and would like to finish implementing highlighting of the search match results in another colour.
with a regex:
eg:
$teststr = "transferase protein is a ras molecule";
$thestr = "\bras\b";
if ($teststr =~ /($thestr)/) {
$matched = $1;
$wherematched = index($teststr, $matched);
}
in this case, i want the regex to match the word "ras" alone (not the unbound 'ras' in "transfeRASe"
however, to do the highlighting of the match result in the HTML output, i need to find out the position of the match made by regex.
the index function above does not go by the regex match position, but instead matches to the first occurrence of $1 ($1 = 'ras') and thus instead matches with "transferase" and gives an index of 7 (i want to get 25). Is there any way to 'link' the regex results with the index function?
I'm aware the index function allows to "skip" to the next match, but this is not what i want because in my case the match position is often variable (i.e. there may be other 'ras' mismatches before the real one that regex properly catches).
can anyone help?
THANKS!!!
Ben