开发者

Regular Expression to replace multiple hyphens with a single one

I wrote a Regular Expression that generates a url like

/abc/deutschland/bbs-tagesfahrten/betz-mode-frotier-开发者_Go百科center-–-tress-teigwaren.html.

Now I want to replace the repeating dashes with a single one. How can I?


String.replaceAll("--+", "-");


Perhaps simpler that any of the suggestions would be:

s/-{2,}/-/g


Use this:

s/---*/-/g


To replace any repeated dashes in the whole URL:

<cfset InputUrl = "/abc/deutschland/bbs-tagesfahrten/betz-mode-frotier-center-–-tress-teigwaren.html">
<cfset CleanUrl = REReplace(InputUrl, "-+", "-", "ALL")>

To work on the file part only:

<cfset PathPart = REReplace(InputUrl, "(.*/).*", "\1")>
<cfset FilePart = ListLast(InputUrl, "/")>
<cfset CleanUrl = PathPart & REReplace(FilePart, "-+", "-", "ALL")>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜