I'm solving an advent of code challenge https://adventofcode.com/2015/day/8. My solution involves the use of regex. I created a pattern on regex 101 https://regex101.com/r/ndI0IO/1 which works properly. The correct solution should show 961 matches, but when I implement it in nim with the re module, It doesn't work properly (gives 361 matches). Here's the code
import std/[re]
let
fir = findAll(file, re"""^"|"$|\\"|\\\\""").len
echo fir
Also, is there a way to escape " without using a multiline string?Also, is there a way to escape " without using a multiline string?
Not in raw string literals. You could use a normal string literal, but then you'd also have to escape backslashes, which would lead to backslash hell.
In Nim, ^ and $ mean start/end of string by default. To get them to mean start/end of line, you need to do:
findAll(file, re("""^"|"$|\\"|\\\\""", {reStudy, reMultiline}))
Thanks for the reply, I got the " matching to work, but it's still not matching ^ and $ lets say this is my input
""
"abc"
"aaa\"aaa"
"\x27
findAll(input, re("^|$", {reStudy, reMultiLine})) should match 8 positions - the begining and end of each of the lines. The reMultiline doesn't seem to help. Is there something I'm missingreMultiLine
ie.
modifier has no benefit, still need the character
r?n"abc"r?n