S
seven.reeds
Hi,
I have a regex question. I have arbitrary text and I want to search
it for a set of terms/substrings. In the simple case of one term
it is easy to find the match(es) and then mark them up with HTML
"span" tags. My issue is with more than one term.
Here is an example to illustrate. If I have the string:
Sarah likes Johnny's cooking
and the single term: "john" then I can match and highlight the match
resulting in:
Sarah likes <span>John</span>ny's cooking
Now what if I have two terms: "Johnny" & "john" -- in that order? I
can easily let myself end up with (in sequence):
<apply Johnny match>
Sarah likes <span>Johnny</span>'s cooking
<apply john match>
Sarah likes <span><span>John</span>ny</span>'s cooking
Ok, so what I want is to be able to search for and mark each term in
the string as long as that term is not already in a "span" clause.
I've done some digging in Friedl's RegEx book but I'm not sure if I
know enough to know what I am looking for?
ideas?
I have a regex question. I have arbitrary text and I want to search
it for a set of terms/substrings. In the simple case of one term
it is easy to find the match(es) and then mark them up with HTML
"span" tags. My issue is with more than one term.
Here is an example to illustrate. If I have the string:
Sarah likes Johnny's cooking
and the single term: "john" then I can match and highlight the match
resulting in:
Sarah likes <span>John</span>ny's cooking
Now what if I have two terms: "Johnny" & "john" -- in that order? I
can easily let myself end up with (in sequence):
<apply Johnny match>
Sarah likes <span>Johnny</span>'s cooking
<apply john match>
Sarah likes <span><span>John</span>ny</span>'s cooking
Ok, so what I want is to be able to search for and mark each term in
the string as long as that term is not already in a "span" clause.
I've done some digging in Friedl's RegEx book but I'm not sure if I
know enough to know what I am looking for?
ideas?