2017-09-18 16 views
1

我不确定我是否在这里问一个真正的问题。 但是,可以使用函数matchidx参数在字符串?的开头搜索。因为它不适合我,也许它应该以这种方式工作。将匹配函数的idx参数与格式为“^ .....”的正则表达式结合使用|朱莉娅0.6

julia> str= " # a comment" 
julia> str[5:end] 
"# a comment" 
julia> match(r"^#", str,5) 

julia> match(r"^#", str[5:end]) 
RegexMatch("#")  
+1

是的它看起来好像你不能同时说'^'意思是行首_and_从索引5开始...... – daycaster

+0

我想你是对的。我一直认为PCRE中的ANCHORED选项只在模式开始处添加^。 –

回答

1

要匹配字符串的开头,必须设置锚定选项。

julia> str= " # a comment" 
julia> reg = r"#" 
julia> reg.match_options = reg.match_options | Base.PCRE.ANCHORED 
julia> match(reg, str,4) 

julia> match(reg, str,5) 
RegexMatch("#")