我正在使用正则表达式将纯文本 URL 转换为可点击的链接。
@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.-]*(\?\S+)? )?)?)@
但是,有时在文本正文中,URL 会每行枚举一个,并在末尾添加分号。真实的URL不包含任何“;”。
http://www.aaa.org/pressdetail.asp?PRESS_REL_ID=275;
http://www.aaa.org/pressdetail.asp?PRESS_REL_ID=123;
http://www.aaa.org/pressdetail.asp?PRESS_REL_ID=124
URL 中是否允许使用分号 (;) 或者分号是否可以被视为 URL 结尾的标记?它如何适合我的正则表达式?
最佳答案
一个semicolon is reserved并且只能用于其特殊目的(这取决于方案)。
第 2.2 节:
Many URL schemes reserve certain characters for a special meaning: their appearance in the scheme-specific part of the URL has a designated semantics. If the character corresponding to an octet is reserved in a scheme, the octet must be encoded. The characters ";", "/", "?", ":", "@", "=" and "&" are the characters which may be reserved for special meaning within a scheme. No other characters may be reserved within a scheme.
关于regex - URL 可以包含分号并且仍然有效吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1178024/