将匹配函数的 idx 参数与形式为“^.....”的正则表达式一起使用 |茱莉亚 0.6
Use of the idx parameter of match function with a regexp of the form "^....." | Julia 0.6
我不太确定我是不是在问一个真正的问题。
但是,可以使用函数match
的idx
参数在字符串的开头进行搜索吗?。因为它对我不起作用,也许它应该那样工作。
julia> str= " # a comment"
julia> str[5:end]
"# a comment"
julia> match(r"^#", str,5)
julia> match(r"^#", str[5:end])
RegexMatch("#")
要匹配字符串的开头,必须设置锚定选项。
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("#")
我不太确定我是不是在问一个真正的问题。
但是,可以使用函数match
的idx
参数在字符串的开头进行搜索吗?。因为它对我不起作用,也许它应该那样工作。
julia> str= " # a comment"
julia> str[5:end]
"# a comment"
julia> match(r"^#", str,5)
julia> match(r"^#", str[5:end])
RegexMatch("#")
要匹配字符串的开头,必须设置锚定选项。
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("#")