REGEX 重写问题以允许连字符 [英] REGEX rewrite issue to allow hyphen
问题描述
我有一个需要重写的 Web 服务.我需要能够在查询中允许连字符或破折号.这是我的重写:
I have a web service that I have a rewrite on. I need to be able to allow hyphens or dash in the query. Here is my rewrite:
rewrite ^/app/api/sanction/([0-9]+)/athleteList/([a-zA-Z0-9,]+)/-([0-9,]+)$ /app/athleteList.phtml?s=$1&l=$2&c=$3 last;
查询工作正常,如下所示:
The query works fine like this:
/app/api/sanction/35172/athleteList/MLEVEL07/25001,24450
但是,当我在此处输入破折号或连字符时,查询将失败.
However when I put a dash or hyphen here, the query will fail.
/app/api/sanction/35172/athleteList/MLEVEL-07/25001,24450
如您所见,我在正则表达式中列出了连字符,不确定我在这里做错了什么...
As you can see, I have the hyphen listed in the regex, unsure of what I may be doing wrong here...
推荐答案
你应该把连字符放在上一组:
You should place the hyphen in the previous group :
([a-zA-Z0-9,-]+)/([0-9,]+)
然而,这将匹配---1020-,-02-1-",我不确定这是你想要的.因此我的第一个命题,现在更正:
This will, however, match "---1020-,-02-1-," and i'm not sure this is what you want. Hence my first proposition, corrected now:
([a-zA-Z0-9,]+)(-([0-9]+))?/-([0-9,]+)
这只会匹配weofhw234fhweo,sdfsff3284982-20423400"而不是--,j2j,f9223-2-3402--0d-f0s-f"
This will match only "weofhw234fhweo,sdfsff3284982-20423400" and not "--,j2j,f9223-2-3402--0d-f0s-f"
这篇关于REGEX 重写问题以允许连字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!