I have Coldfusion web page and need code either Coldfusion or a Regular Expression to strip out URL's (multiple) in a string. They are run together with no line breaks or commas separating them. Note all the URLs are 'full' meaning they end with a page or document file type ending in '.doc' or '.txt' or '.pdf'.
example string = "http://xxxx.xxxx.com/apps/libs/hdldocs/pwr_voltage/lmz14202/docs/lmz14202_to-pmod7-ep.pdfhttp://xxxx.xxxx.com/ap
ps/libs/hdldocs/pwr_voltage/lmz14202/docs/lmz14202_to-pmod7-ep.pdfhttp://xxxx.xxxx.com/apps/libs/hdldocs/pwr_voltage
/lmz14202/docs/lmz开发者_Go百科14202h-data.pdfhttp://xxxx.xxxx.com/apps/libs/hdldocs/pwr_voltage/lmz14202/docs/lmz14202_to-pmod7-
ep.pdfhttp://xxxx.xxxx.com/apps/libs/hdldocs/pwr_voltage/lmz14202/docs/lmz14202_to-pmod7-ep.pdfhttp://xxxx.xxxx.co
m/apps/libs/hdldocs/pwr_voltage/lmz14202/docs/lmz14202h-data.pdf"
Either a Coldfusion or Regular Expression would help! Thanks.
<cfscript>
examplestring = "http://xxxx.xxxx.com/apps/libs/hdldocs/pwr_voltage/lmz14202/docs/lmz14202_to-pmod7-ep.pdfhttp://xxxx.xxxx.com/apps/libs/hdldocs/pwr_voltage/lmz14202/docs/lmz14202_to-pmod7-ep.pdfhttp://xxxx.xxxx.com/apps/libs/hdldocs/pwr_voltage/lmz14202/docs/lmz14202h-data.pdfhttp://xxxx.xxxx.com/apps/libs/hdldocs/pwr_voltage/lmz14202/docs/lmz14202_to-pmod7-ep.pdfhttp://xxxx.xxxx.com/apps/libs/hdldocs/pwr_voltage/lmz14202/docs/lmz14202_to-pmod7-ep.pdfhttp://xxxx.xxxx.com/apps/libs/hdldocs/pwr_voltage/lmz14202/docs/lmz14202h-data.pdf";
aHREF = examplestring.split("http://");
</cfscript>
I wrote it as a script block, but it works just as well with standard cfset calls.
You end up with an array of urls with the http:// stripped off the front. If the first thing in the string is a url, then you will end up with an empty array element in the first position, but that should give you a good start. It should also be considerably quicker than using the ColdFusion functions with large quantities of data as it goes direct to the underlying java.lang.String object.
<cfset myurls = ListToArray(ReplaceNoCase(str, "http://", "#chr(7)#http://", "all"), chr(7))>
as user662486 pointed out, there is not reason to do this with a regular expression. the code above will return an array with each element containing the full url.
精彩评论