1

I want to find out if my string contains a certain substring and return true if it does and false if it doesnt.

regex = /^[a-z0-9]*(TEST)+'[a-z0-9]*$/;
if(myString.contains(regex)) {
  // do something
}
Matt
  • 43,482
  • 6
  • 101
  • 102
Flexo
  • 2,506
  • 3
  • 21
  • 32

1 Answers1

3

With the ^ and $ anchors, you are pretty much preventing any sub-match, because they require the entire myString to match the regex. So the first step is to remove those anchors. Then:

if (regex.test(myString)) {
Matt
  • 43,482
  • 6
  • 101
  • 102