Wednesday 15 July 2015

regex - Highlighting Palindromes using Javascript -


I want to highlight all 6 letters palindromes displayed on a webpage. I got this Javascript function and I think I have it. Accordingly has been adapted accordingly.

  function highlight () {var query = new RegExp ("([ATCG]) ([ATCG]) ([ATCG]) (\\ 3) (\\ 2) (\\) 1) "," Jim "); Var E = document.getElementById ("Search Text"). InnerHTML; Var Envel = E. Location (/ (< | ) / igm, ""); Document.getElementById ("Search Text"). InnerHTML = enew; Var newe = enew.replace (query, ""); Document.getElementById ("Search Text"). InnerHTML = newe; }  

When I run the function (clicking on the link) does not highlight any text. It works if there is just put a regular string, so I thought it was regular Expression is giving the problem but tested it online and found that it works.

breakdown of another intuivite , which includes upper and lower case matches:

  Function Highlabel () {var e = document.getElementById ("Search Text"); E.innerHTML = e.innerHTML .replace (/ ( 

try it below

  function highlabel () {var e = document.getElementById ("searchtext"); E.innerHTML = e.innerHTML .replace (/ ( 
  Duration {Background: #FF9; Color: # 555;} body {font family: aerial, helvetica, sans-serif; Padding: 0 1AM;} P {margin: .8 AM 0}}  
  & lt; Div id = "searchtext" & gt; & Lt; P & gt; Javascript is a programming language of the web, on the great CGTTGCAATTAAGGCCGG browser, desktop, game consoles, tablets, and smart phones- JavaScript Pulpap interpreters are included in the first class tasks by planning, using rules, using this book and learning to have JavaScript . & Lt; / P & gt; & Lt; P & gt; The name oooooooooooooooooo "javascript" is actually somewhat misleading rerrer & lt; Period & gt; Except for the & lt; / Span & gt; To become a strong and efficient general purpose language for a scripting-language fraction roots. & Lt; / P & gt; & Lt; / Div & gt;  


No comments:

Post a Comment