A whitelist of templates in a template set with a controlled multi-page window in regular expression

I want the following examples to return a match

  • I like foobar.com
  • I like google.com and foobar.com
  • I like foobar.com and google.com
  • I like foobargoogle.com and google foobar.com
  • I like yahoo.com and foobar.com
  • I like foobar.com and yahoo.com
  • I like foobaryahoo.com and yahoo foobar.com

I do not want the following examples to return a match

  • I like yahoo.com
  • I like foobar yahoo.com
  • I like google.com
  • foobar google.com
  • google.com yahoo.com
  • foobar google.com foobar yahoo.com

. ,

Regex:

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

"google.com" "yahoo.com", , "foobar.com".

. foobar.com, google.com

, , "google.com" "yahoo.com" : "\ w +.com".

:

  • google.com yahoo.com - . , -
+2
2

PCRE (* SKIP) (* F).

(?:google|yahoo)(?:\.com)?(*SKIP)(*F)|(?:(?!google|yahoo)\w)+\.com
^                                    ^                           ^
|------Part you don't want-----------|------------Part you want--|

DEMO

:

  • (?:google|yahoo)(?:\.com)? google yahoo .com. . .

  • (?:google|yahoo)(?:\.com)?(*SKIP)(*F)| PCRE (*SKIP)(*F) . | , google yahoo. .

  • (?:(?!google|yahoo)\w)+\.com , , google yahoo.

  • \.com , .com
+1

.
, .

 # (?:\w(?<!google)(?<!yahoo))+\.com

 (?:
      \w                # Match words but not google or yahoo behind
      (?<! google )
      (?<! yahoo )
 )+
 \. com
+1

Source: https://habr.com/ru/post/1569124/


All Articles