(too long for comments)
I don't understand why this gives zero for both
reFind("(?=dev)\.mydomain\.com$", "subdomaindev.mydomain.com") = 0
Verily, me too. However, I came across this topic , which offers a plausible explanation. Rephrase (using your values):
Looks ahead from the face on which they are located, and you placed it in front . . So, what you have is actually saying "everything that ends on .mydomain.com if the first three characters starting at this position ( .my ) are not dev ", which is always true.
.. or in the case of (?=dev) always always false, because obviously .my characters .my never be equal to dev .
Further search opened a detailed blog entry by Adam Cameron on regular expressions and browsing . The Negative Views section contains an example expression used to validate a string that does not contain the word CAT:
^(?!.*CAT).*$
A blog entry provides a better explanation, but mostly uses ^ (start), $ (end) and .* (Zero or more characters) to search the entire string. While your current expression only searches for characters following it, that is, ".mydomain.com".
If I understand correctly, you can use the approach described above to confirm that the supplied line does not end with "dev.mydomain.com". Just change "CAT" to the substring you are trying to match ... err ... does not match. Not very verified, but something like that:
reFind("^(?!.*dev\.mydomain\.com$).*$","subdomain.mydomain.com") reFind("^(?!.*dev\.mydomain\.com$).*$","subdomaindev.mydomain.com")
Results:
- 0 ==> "subdomaindev.mydomain.com"
- 1 ==> "subdomain.mydomain.com"
Disclaimer: I am not an expert on regular expression, fantasy in any way , so itβs quite possible that there are better options. However, I hope this helps explain why the current expression does not work as you expected.
Update:
As noted in @zabuuq's comment, the final working expression:
^(?!.*dev\.mydomain\.com).*\.mydomain\.com$