Please give me examples of text which match this regex:
root/(.+)-go-to-products.php
It matches any string that has root/ followed by one ore more characters other than newline followed by -go-to-products followed by any one char(other than newline) followed by php and these can occur anywhere in the string.
It'll match:
root/f-go-to-products.php
root/foo-go-to-products.php
root/foo-go-to-products.php5 # Because you are not using anchor
http://stackoverflow.com/questions/3905066?root/f-go-to-products.php # no anchor
root/../foo-go-to-products.php # . can match a literal . and /
and also
root/foo-go-to-products-php # because . is a meta char.
But not
root/-go-to-products.php # because .+ expects at least 1 char.
To match the . before php literally escape it as: root/(.+)-go-to-products\.php
Also if you are using the regex just for matching and you don't want to extract what is matched by .+ you can drop the parenthesis and just use:
root/.+-go-to-products\.php
To ensure a match does not happen when the pattern is found as a substring you should anchors as: ^root/.+-go-to-products\.php$
Since a . matches a literal . and a /, your regex can match potentially dangerous inputs like: root/../bar/foo-go-to-products.php. In this input the php file foo-go-to-products.php is not present in the root directory but is present in the root/../bar directory which is bar directory at the same level as root.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With