-2

I have a string "platform:17.01.02" and I want to search for "17.01.02" which I'm giving through a variable.

a = "platform:17.01.02"
b = "17.01.02" (has to taken from user)

a.search(/b/)

The above statement search for "b" and not for variable value "b". Can any one help how can i search that?

Jyothi Babu Araja
  • 10,076
  • 3
  • 31
  • 38
Anuj Gupta
  • 125
  • 1
  • 8

1 Answers1

-1

Try this:

var a = "platform:17.01.02";
var b = "17.01.02";

console.log(a.search(new RegExp(b))); //9

If you just want to know if a contains b, use:

a.indexOf(b) >= 0
Arg0n
  • 8,283
  • 2
  • 21
  • 38
  • that will yield unexpected results when the user accidentally types in regex metacharacters – Bergi Mar 21 '17 at 11:29