I would recommend (if you have windows) “the regex coach”. In the top
you put your regex, in the bottom your text to match, and it’ll show
you what is going on. My first guess is that nginx regex syntax is
different from perl, but I could also have made a mistake or two.
The regex I wrote, in human-speak, is:
$url =~ s#/[^/].?([0-9])..html$#/showthread.php?t=$1#i;
$url =~ s
(substitution regex against $url variable)
# #i;
using # as the delimiter since we’re using slash in our regex, case
insensitive matching
/[^/].*
start with a slash, then match every character afterwards that is not
a slash, but as few characters as possible
([0-9]).*
ok that was an error of mine, it should have read:
([0-9].*)
which is, match a group of characters whose values can contain digits
0-9, which will be stored in $1, as many characters as you can find
that match.
.html$
then the period character, then “html”, at the end of the line ($
means end of line)
#/showthread.php?t=$1#
replace what we matched in the first part with what follows:
/showthread.php?t=
and then whatever we matched earlier in ([0-9].*)
So the new regex after fixing my error would be:
$url =~ s#/[^/].?([0-9].).html$#/showthread.php?t=$1#i;
In perl anyway.