Answer the question
In order to leave comments, you need to log in
How to find common matches of two regular expressions?
Hello.
Imagine we have a line:
const text = 'hemidemisemiquaver';
We also have two masks:
const s1 = 'emi';
const s2 = 'm.se';
Matches of the first mask should be in italics and the second in bold.
You also need to take into account that if the match applies to the first and second at the same time, then this match must have both styles.
In this example, it will be like this h emi d e mi s e mi quaver
In general, I broke my whole head, but I can’t implement it.
Help with an idea or example code, please)
Answer the question
In order to leave comments, you need to log in
php has similar_text and soundex , look for analogues for js.
Calculates the degree of similarity of two strings using the algorithm described in Programming Classics: Implementing the World's Best Algorithms by Oliver (ISBN 0-131-00413-1).
General - can not be.
Because there will be a violation of the correctness of the tag, for example: <b><i>общее</b></i>
You decide: in what order you add tags: first italic, then bold, or vice versa.
When performing the 2nd step, you are already doing the operation on the TOKENS (without tags) obtained in the 1st step, and not on the original string, in order to avoid intersections when tagging (as in the example above).
An idea in 5 minutes, I don’t pretend to be beautiful and lack a bicycle:
create a new variable text_html , in which each letter from text will be wrapped in a tag
let text_html = '<span>h</span><span>e</span> ... <span>r</span>';
// создаете её программно, естественно, работая с DOM
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question