Adobe CQ5 regex that will reject an entire string if either of 2 different substrings are found within the string

StackOverflow https://stackoverflow.com/questions/22723176

Question

Adobe CQ5 dialog editor, regex property:

I am regex challenged so forgive me, but it seems a simple task and I just can't seem to find the right fit elsewhere on the internet. Every suggestion that looks right just doesn't seem to work in adobe's regex field.

I want the content admin to supply a relative URL to a "thank you" page. I don't need anything super fancy, I simply want to reject the admin's input if "http" or ".com" is found anywhere within the text supplied by the admin.

Examples for admin supplied input:
URL                                       REGEX VALIDATES INPUT AS SUCCESS?
http://www.domain.com/questions           No. string has both "http" and ".com"
https://www.domain.com/mail               No. string has both "http" and ".com"
https://www.domain.net                    No. string has "http"
oopshttp://www.domain.net                 No. string has "http"
www.domain.com/mail                       No. string has ".com"
/subdomain/thankyou.html                  YES! string has neither "http" or ".com"

Ideally, the rejection of "http" and ".com" would supplement what I currently have: Which is the string must start with a forward slash "/" and end in ".html" which is:

/^\/.+?\.html$/

Any help is appreciated, thank You in advance

Was it helpful?

Solution 2

This can work with negative lookahead:

^\/(?!.*?(http|\.com)).+?\.html$

Online Demo: http://regex101.com/r/dN8uV2

OTHER TIPS

^/.+\.html$ should work completely fine.

Autopsy:

  • ^ the start MUST match whatever is next:
  • / a literal slash (if your modifier is a slash you need to escape this to \/)
  • .+ match as much as possible (any character 1 to infinity times)
  • \.html the literal string .html
  • $ the end MUST be here

Regular expression visualization

Debuggex Demo

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top