PDA
PDA

Reputation: 774

what's wrong with this javascript regexp?

Trying to find instances of "N/A" in markup and swap out with something else,

var $reg = new RegExp('[Nn]/[Aa]');

other variations were:

Upvotes: -1

Views: 59

Answers (2)

David Thomas
David Thomas

Reputation: 253496

I'd suggest:

stringToSearchIn.replace(/(N\/A)/gi,'words to replace with');
  1. \/ escapes the slash, as the / character delimits the regex string, and
  2. the gi at the end:
    • g is for a global search, so it doesn't stop after the first match, and
    • i is case-insensitive (so it'll match n and N, a and A.

JS Fiddle demo

Upvotes: 2

Michael Frederick
Michael Frederick

Reputation: 16714

You could just use this one:

N\/A

Upvotes: 0

Related Questions