ruby正则表达挂起
发布时间:2020-12-17 01:49:12 所属栏目:百科 来源:网络整理
导读:我编写了一个 ruby脚本来处理大量文档,并使用以下URI从文档的字符串表示中提取URI: #Taken from: http://daringfireball.net/2010/07/improved_regex_for_matching_urlsURI_REGEX = /( # Capture 1: entire matched URL (?: [a-z][w-]+: # URL protocol an
我编写了一个
ruby脚本来处理大量文档,并使用以下URI从文档的字符串表示中提取URI:
#Taken from: http://daringfireball.net/2010/07/improved_regex_for_matching_urls URI_REGEX = / ( # Capture 1: entire matched URL (?: [a-z][w-]+: # URL protocol and colon (?: /{1,3} # 1-3 slashes | # or [a-z0-9%] # Single letter or digit or '%' ) | # or wwwd{0,3}[.] # "www.","www1.","www2." … "www999." | # or [a-z0-9.-]+[.][a-z]{2,4}/ # looks like domain name followed by a slash ) (?: # One or more: [^s()<>]+ # Run of non-space,non-()<> | # or (([^s()<>]+|(([^s()<>]+)))*) # balanced parens,up to 2 levels )+ (?: # End with: (([^s()<>]+|(([^s()<>]+)))*) # balanced parens,up to 2 levels | # or [^s`!()[]{};:'".,<>???“”‘’] # not a space or one of these punct chars ) )/xi 它适用于99.9%的所有文档,但在遇到文档中的以下标记时总是挂起我的脚本:token =“synsem:local:cat:(subcat:SubMot,adjuncts:Adjs,subj:Subj),“ 我使用的是标准的ruby regexp oeprator:token = ~URI_REGEX,我没有收到任何异常或错误消息. 首先,我尝试解决将正则表达式评估封装到Timeout :: timeoutblock中的问题,但这会降低性能. 关于如何解决这个问题的任何其他想法? 解决方法
为什么重塑
the wheel?
require 'uri' uri_list = URI.extract("Text containing URIs.") (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |