samedi 27 décembre 2014

Whitelisting of Patterns in a Set of Patterns with controlled Multi Occurance in Regex

I want the following examples to return match



  • I like foobar.com

  • I like google.com and foobar.com

  • I like foobar.com and google.com

  • I like foobargoogle.com and googlefoobar.com

  • I like yahoo.com and foobar.com

  • I like foobar.com and yahoo.com

  • I like foobaryahoo.com and yahoofoobar.com


I don't want the following examples to return match



  • I like yahoo.com

  • I like foobaryahoo.com

  • I like google.com

  • I like foobargoogle.com

  • I like google.com and yahoo.com

  • I like foobargoogle.com and foobaryahoo.com


Note - It's not an equal match but a contain match


I tried the following Regex Pattern:



(?!(^.*((google)|(yahoo))\.com.*$))(^.*\w+\.com.*$)


but as soon as either "google.com" or "yahoo.com" occured, it terminated with no match even if "foobar.com" occured before it.


eg. I like foobar.com but not google.com


Basically, I want it to ignore "google.com" and "yahoo.com" anywhere in the string and detect any other type: "\w+.com".


Note:



  • google.com and yahoo.com are just examples. So, it should ignore match set of any string length of alphanumeric characters

  • ignore case and whitespace


Aucun commentaire:

Enregistrer un commentaire