Firstly I think your regex needs some fixing. Let's look at what you have:
test.com(\/\??index_.*.php\??(.*)|\/\?(.*)|\/|)+(\s)*(?!.)
The case where you use the optional ?
at the start of index...
is already taken care of by the second alternative:
test.com(\/index_.*.php\??(.*)|\/\?(.*)|\/|)+(\s)*(?!.)
Now you probably only want the first (.*)
to be allowed, if there actually was a literal ?
before. Otherwise you will match test.com/index_fb2.phpanystringhereandyouprobablydon'twantthat
. So move the corresponding optional marker:
test.com(\/index_.*.php(\?(.*))?|\/\?(.*)|\/|)+(\s)*(?!.)
Now .*
consumes any character and as much as possible. Also, the .
in front of php
consumes any character. This means you would be allowing both test.com/index_fb2php
and test.com/index_fb2.html?someparam=php
. Let's make that a literal .
and only allow non-question-mark characters:
test.com(\/index_[^?]*\.php(\?(.*))?|\/\?(.*)|\/|)+(\s)*(?!.)
Now the first and second and third option can be collapsed into one, if we make the file name optional, too:
test.com(\/(index_[^?]*\.php)?(\?(.*))?|)+(\s)*(?!.)
Finally, the +
can be removed, because the (.*)
inside can already take care of all possible repetitions. Also (something|)
is the same as (something)?
:
test.com(\/(index_[^?]*\.php)?(\?(.*))?)?(\s)*(?!.)
Seeing your input examples, this seems to be closer to what you actually want to match.
Then to answer your question. What (?!.)
does depends on whether you use singleline
mode or not. If you do, it asserts that you have reached the end of the string. In this case you can simply replace it by \Z
, which always matches the end of the string. If you do not, then it asserts that you have reached the end of a line. In this case you can use $
but you need to also use multi-line mode, so that $
matches line-endings, too.
So, if you use singleline
mode (which probably means you have only one URL per string), use this:
test.com(\/(index_[^?]*\.php)?(\?(.*))?)?(\s)*\Z
If you do not use singleline
mode (which probably means you can have multiple URLs on their own lines), you should also use multiline
mode and this kind of anchor instead:
test.com(\/(index_[^?]*\.php)?(\?(.*))?)?(\s)*$