Stdlib: nre: Convenience proc `contains` added.
This commit is contained in:
parent
299989f3aa
commit
4f9b498103
1 changed files with 10 additions and 0 deletions
|
|
@ -566,6 +566,16 @@ proc findAll*(str: string, pattern: Regex, start = 0, endpos = int.high): seq[st
|
|||
for match in str.findIter(pattern, start, endpos):
|
||||
result.add(match.match)
|
||||
|
||||
proc contains*(str: string, pattern: Regex, start = 0, endpos = int.high): bool =
|
||||
## Determine if the string contains the given pattern between the end and
|
||||
## start positions:
|
||||
## - "abc".contains(re"bc") == true
|
||||
## - "abc".contains(re"cd") == false
|
||||
## - "abc".contains(re"a", start = 1) == false
|
||||
##
|
||||
## Same as ``isSome(str.find(pattern, start, endpos))``.
|
||||
return isSome(str.find(pattern, start, endpos))
|
||||
|
||||
proc split*(str: string, pattern: Regex, maxSplit = -1, start = 0): seq[string] =
|
||||
## Splits the string with the given regex. This works according to the
|
||||
## rules that Perl and Javascript use:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue