regex - Write a regular expression that contains three instances of a letter,with exceptions -
how write regular expression matches strings containing 3 instances of y (capital y) excluding instances of y are:
preceded a: digit (0-9), + (plus sign) , - (minus sign), " (double quote) or (capital a), ignoring white space and
followed a: u, ], q, t , o, or t.
part of date (may)
for example:
- y y y (matches)
- y y 21- yu&rp12be15 (does not match)
- y y 21- yu&rp12be15y (does match)
- f19 vs40ketapy y y (does match)
- y 25- 15be22y y (does match)
- y g^24- tu&or15be13y f/m 4yo 14may gccn (does not match)
- y g^24- tu&or15be13y f/m 4yo 14may gccy (does match)
i took try on regex101 (click here), i'm not sure how handle more complex examples.
you try this:
//if necessary, loop through strings var str = 'f19 vs40ketapy y y'; //remove matches var str = str.replace(/\d\s?y|\+\s?y|\-\s?y|\"\s?y|a\s?y|yu|y\]|yq|yt|y0|yt/g, ''); //check 3 y's in remaining string if (str.match(/y/g).length == 3) { alert('match'); }
Comments
Post a Comment