-1

I have been tasked with checking for certain patterns in an email subject and not allowing a user to send the email based on those patterns. Problem is... I have to use an existing regex. The existing regex uses matching patterns to allow the user to send. In my case, I want to check for a pattern to not allow. I have googled, and attempted a million different ways of doing this. Can't get it all to work.

So here is what I have to check for: FW: FWD: RE: FW: RE; FW- RE- FW, RE,

So here is the exisiting pattern that I need to search for ANYWHERE not just beginning:

^[\w\d\s\+\-\/\\~!@#$%&*()_.,'?\u2600\u2715\u2716\u2713\u2714\u2606\u260E\u00A9\u00A3\u2612\u2614\u2615\u2618\u2619\u261A\u261B\u261C\u261D\u261E\u261F\u00AE\u00A2\u00BC\u00BD\u00BE\u2122\u263D\u263E\u2668\u2672\u2661\u2662\u2663\u2664\u2665\u2666\u2669\u266A\u266B\u266C\u2672\u267B\u267E\u267F\u2692\u2693\u2694\u2698\u269C\u26A0]+$
Mike Schwartz
  • 2,084
  • 1
  • 15
  • 26
  • 1
    ...Please learn how regexs work (i.e. [Google "regex guide"](https://www.google.com/search?q=regex+guide&oq=regex+guide&aqs=chrome..69i57.1143j0j7&sourceid=chrome&es_sm=93&ie=UTF-8)). Then you'll see that it's as simple as removing the `^` at the front to make it work anywhere. if you also don't want it to be anchored to the end, remove the `$` at the end. – Fund Monica's Lawsuit Apr 20 '15 at 21:55
  • Which language are you using ? – Pedro Lobito Apr 20 '15 at 22:05
  • Language is javascript – Mike Schwartz Apr 21 '15 at 00:51

1 Answers1

0

You just have to add a negative lookahead to your pattern:

(?!.*?\b(?:FWD?|RE)[-:;,])

The .*? will enforce the condition anywhere in the pattern.

So the pattern ends up like this:

^(?!.*?(?:FWD?|RE)[-:;,])[\w\d\s\+\-\/\\~!@#$%&*()_.,'?\u2600\u2715\u2716\u2713\u2714\u2606\u260E\u00A9\u00A3\u2612\u2614\u2615\u2618\u2619\u261A\u261B\u261C\u261D\u261E\u261F\u00AE\u00A2\u00BC\u00BD\u00BE\u2122\u263D\u263E\u2668\u2672\u2661\u2662\u2663\u2664\u2665\u2666\u2669\u266A\u266B\u266C\u2672\u267B\u267E\u267F\u2692\u2693\u2694\u2698\u269C\u26A0]+$
Plop
  • 1
  • 1
  • Ok this one is really close - now I just need to search only for that pattern on its own and not part of another word. – Mike Schwartz Apr 21 '15 at 14:32
  • That's what the `\b` is for. Post an example, I'm not sure I understand what you mean. – Plop Apr 23 '15 at 19:23