Regex to match any character or fullstop?
I'm trying to create a regex that takes a filename like:
/cloud-support/filename.html#pagesection
and redirects it to:
/cloud-platform/filename#pagesection
Could anyone advise how to do this?
Currently I've got part-way there, with: 开发者_如何转开发
"^/cloud-support/(.*)$" => "/cloud-platform/$1",
which redirects the directory okay - but still has a superfluous .html
.
Could I just match for a literal .html
with optional #
? How would I do that?
Thanks.
Maybe something like this:
"^/cloud-support/(.*?)(\.html)?(#.+)$" => "/cloud-platform/$1$3"
where the first group is a non-greedy match (.*?)
"^/cloud-support/(\w+).html(.*)" => "/cloud-platform/$1$2"
Would something like this work?
"^/cloud-support/([^.]+)[^#]*(.*)$" => "/cloud-platform/$1$2"
Can you try the regex
"^/cloud-support/(.*)\.html(#.*)?$"
The \.html
part matches .html
while (#.*)?
allows an optional #
plus something.
精彩评论