nim语言的re模块是包装了c语言的库pcre. 提供了很多的proc供调用.
主要的 函数就是find, findBounds, findAll
1. findBounds查找某个规则的字符串.
例如:
import re
let
currentline = "[chapter Uno] and {style} [chapter dos]."
regex = re"\[chapter(\s+)(.*?)\]"
proc testStrings() =
var matches: seq[string] = @["", ""]
let (start, e) = currentline.findbounds(regex, matches)
echo "testStrings"
echo "start: ", start, " end: ", e, " matches: ", matches.repr
proc testStringIndices() =
var matches: seq[string]
matches.newSeq(2)
let (start, e) = currentline.findbounds(regex, matches)
echo "testIndices"
echo "start: ", start, " end: ", e, " matches: ", matches.repr
proc testIndices() =
var matches: seq[tuple[first, last: int]]
matches.newSeq(2)
let (start, e) = currentline.findbounds(regex