Ranon Kahn Ranon Kahn - 1 year ago 73
Javascript Question

How to highlight a substring containing a random character between two known characters using javascript?

How to highlight the substring 'NxG' where 'x' could be any character between 'N' and 'G' in a string like "ARSTNFGATTATNMGATGHTGNKGTEEFR" with a new FG and BG color?

datatable(DF, options = list(rowCallback=JS("function(row,data) {
data[0] = data[0] .replace(/NxG/g,'<span style=\"color:blue; font-weight:bold\"\">NxG</span>');
$('td:eq(0)', row).html(data[0] );}" ), dom = 't'))

Answer Source

I think the regex you want is: /N[A-Z]G/g

If you also want it to work for lower case: /N[A-Za-z]G/g

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download