简体   繁体   English

对Coldfusion的REGEX帮助 - 在URL中,删除? 之后的一切

[英]REGEX Help for Coldfusion - In a URL, removing the ? And everything after

I'm looking for some REGEX help Given the following URL: http://news.cnet.com/8301-13924_3-10315534-64.html?part=rss&subj=news&tag=2547-1_3-0-20 我正在寻找一些REGEX帮助给出以下URL: http ://news.cnet.com/8301-13924_3-10315534-64.html?part = rss&sububs = news&tag = 2547-1_3-0-20

What is the REGEX to obtain the following: 获得以下内容的REGEX是什么:

http://news.cnet.com/8301-13924_3-10315534-64.html http://news.cnet.com/8301-13924_3-10315534-64.html

Thus removing the ? 从而删除? and everything after it 以及它之后的一切

Thanks, B 谢谢,B

You can certainly use a regex for this, but it would be more efficient to use 你当然可以使用正则表达式,但使用它会更有效

listfirst(theurl, '?')

which finds the first part of a list delimited by question marks. 它找到由问号分隔的列表的第一部分。

In ColdFusion you could use regex replace: 在ColdFusion中,您可以使用正则表达式替换:

myURL = REReplace(myURL,"\?.*$","")

That would leave you with everything before the question mark. 这会让你在问号之前得到一切。

This regular expression will do the trick: 这个正则表达式可以解决这个问题:

^([^?]+)

Just take the second capture group from the match (the first capture group is always the original string itself if it matched). 只需从匹配中获取第二个捕获组(如果匹配,则第一个捕获组始终是原始字符串本身)。

@Ben Doom: If I'm not mistaken, the #url# variable is a complex object and cannot be treated as a string or list. @Ben Doom:如果我没弄错的话,#url#变量是一个复杂的对象,不能被视为字符串或列表。 The way I go about getting everything before the query string is: 我在查询字符串之前获取所有内容的方式是:

<cfset myURL = "http://" & #cgi.HTTP_HOST# & #cgi.SCRIPT_NAME# />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM