diff options
author | Flaviu Tamas <tamasflaviu@gmail.com> | 2015-01-18 13:45:56 -0500 |
---|---|---|
committer | Flaviu Tamas <tamasflaviu@gmail.com> | 2015-01-18 13:45:56 -0500 |
commit | 7bce00b4cdb31cd5a72230b937d781778954eb67 (patch) | |
tree | 0afb2ed307f3205f8555a791e7cb8222d58e0d75 /src/nre.nim | |
parent | 0b24ba0d26f4bd1abb11d3cbe10b06d5ee7bb433 (diff) | |
download | Nim-7bce00b4cdb31cd5a72230b937d781778954eb67.tar.gz |
Add escapeRe
Diffstat (limited to 'src/nre.nim')
-rw-r--r-- | src/nre.nim | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/nre.nim b/src/nre.nim index b4ce99c65..d907cae62 100644 --- a/src/nre.nim +++ b/src/nre.nim @@ -291,6 +291,7 @@ proc initRegex(pattern: string, options: string): Regex = proc re*(pattern: string, options = ""): Regex = initRegex(pattern, options) # }}} +# Operations {{{ proc matchImpl(str: string, pattern: Regex, start, endpos: int, flags: int): RegexMatch = new(result) result.pattern = pattern @@ -442,3 +443,9 @@ proc replace*(str: string, pattern: Regex, proc replace*(str: string, pattern: Regex, sub: string): string = return str.replace(pattern, proc (match: RegexMatch): string = sub % match.captures.toSeq ) + +# }}} + +let SpecialCharMatcher = re"([\\+*?[^\]$(){}=!<>|:-])" +proc escapeRe*(str: string): string = + str.replace(SpecialCharMatcher, "\\$1") |