I am using jQuery to highlight summaries within an article, and struggling with my regex Am
I am trying to match a specific word which is a word within an HTML tag (and
Is not in any particular feature like), is not part of the second word and is not already there & lt; A & gt;
tag.
Then I have a & lt; Abbr & gt;
I will wrap the tag and a glossary with a link.
I have found a little way, my current ridge looks like this:
(\> [^ \ & gt;] * \ W) abrr ( \ W [^ \ & gt; =] * \ & lt;)
Where "ABRR" is an abbreviation, which I am trying to match. This type of works, but if ABRR is not the first word of a line, or if it is a and lt; A & gt;
is inside the tag.
"abbr" I want to match:
& lt; P & gt; Home Ebid ipsum & lt; / P & gt; & Lt; P & gt; ABBR Leram ABRR & lt; / P & gt; & Lt; Ul & gt; & Lt; Li & gt; ABBR ABRR & lt; / Li & gt; & Lt; Li & gt; Abbr & lt; / Li & gt; & Lt; / Ul & gt;
While I do not match any of these:
& lt; P & gt; & Lt; A href = "abbr.html" & gt; ABBR & Lt; / A & gt; & Lt; / P & gt; & Lt; Img src = "abbr.jpg" /> & Lt; P & gt; Lormabbripsum & lt; / P & gt;
To do this, I am choosing to place all the HTML within my article for the purpose of replacing a string. My JS looks like this
$ GetJSON ("glossary", function (data) {var str = $ ('article-entity'). Html (); var i; for (I = 0; i
We can use the limitations of words 'b' in terms of words, however Is not right. Suppose you were looking for IA. It will get a match in the CIA. Because the term words are part of the boundaries.
In addition to this, we can use the positive Lookhead (LA) and Negative LookAheads (NLA) for look forward and decide on the basis of the content.
I do not think regex is ideal because of the word boundary issue and because while casting such a wide net in an HTML document, things can get hair (if you have non-ideal HTML) / ^ [^ & Gt;] *) \ b # token: \ b # word limit abbr # literal abbruck \ token: \ b # word limit (? = # Open ola (?! # Nella [^ & gt;] * # Negative character class (inner characters are included) # None: & gt; # * Repeats zero or more often # / Literate & lt; / a & gt;) # Close NLA [^> * Repeats zero or more times #Literal & lt;) # Close LA
No comments:
Post a Comment