Or you can use parseutils: import parseutils const line = " ; abc " const commentChars = {'#', ';'} var res = "" let pos = skipUntil(line, commentChars) if pos != line.len: let start = pos + 1 discard parseUntil(line, res, '\0', start) echo("found a comment: ", res, " starting at: ", start)
I tried to use scanp before but it offers no convenience, and so you need to use custom logic and has weird syntax.