Ayush Bahuguna Ayush Bahuguna - 1 year ago 77
Javascript Question

Regex test should return true only when pattern matches throughout the string. Javascript

I really didn't how to put it in a form of question, but I have to write a function that matches a string for a pattern


the string should be of format where each alphabet is surrounded by "+" sign.

I came up with this expression,
var letter = /\+\w\+/;
. The problem with this is that it returns true even if the pattern matches just once throughout the string.

for example, it returns true for
, but it returns true for

Thank You

Answer Source

You can match the reverse and throw the error

Something like

"+f+++a=+b+=c++".match(/(\w=|=\w)/g) == null ; //false


"+f+++a+b+c++".match(/(\w=|=\w)/g) == null ; //true
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download