I want to process a String, in which I want to find multiple strings, i am trying to make some highlighter in html text in java..
Example:
Find and process phrases table, row, primary key in Each table row contains a primary key column
The text is html text with tags like <b>,<img..>...
if there is ignorable tag in the middle of phrase for ex. primary <b>key</b>(ignorable tag is the tag that does not interrupt the text meaning like <b> or <i>, on the other hand tag like <div> interrupts the text meaning) the phrase can be replaced.
if one phrase is a subphrase of other phrase, the longer has a higher priority. for ex. searching for table row and row contains in the mentioned text the second one should be proccesed
My first pseudocode was somethin like this:
for (each phrase)
while(tex.hasNext(phrase)) do
processPhraseInText(text,phrase)
end-while
end-for
It was working, but the text was traversed phrases.count() times and I am searching a faster way to process all the prases at once
I want to try the Regular expression and pattern-matcher to use in this.
I came up with two ways, 1. create one regular expression for all the phrases looking somehow like this: regex1|regex2|..|regexN or 2. to create for every phrase one regex( and one Matcher object)
what could be the better way? or is there some totaly different way or existing library for this? isnt the second way with many matchers the same like the sollution I already have?
If you make a regex for each phrase, you still have to loop over the text a couple of times.
If you make one regex
regex1|regex2|..|regexN, you can search through the text in one pass.This would be faster with many phrases.