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
}
1

1 Answer 1

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)) {
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.