2017-09-18 13 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("#")