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:

  1. preceded a: digit (0-9), + (plus sign) , - (minus sign), " (double quote) or (capital a), ignoring white space and

  2. followed a: u, ], q, t , o, or t.

  3. part of date (may)

for example:

  1. y y y (matches)
  2. y y 21- yu&rp12be15 (does not match)
  3. y y 21- yu&rp12be15y (does match)
  4. f19 vs40ketapy y y (does match)
  5. y 25- 15be22y y (does match)
  6. y g^24- tu&or15be13y f/m 4yo 14may gccn (does not match)
  7. 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

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -