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")>
精彩评论