Search code examples
pcrenim-lang

Do a Nim regex modifier just like Perl one


How is Nim regex PCRE modifier done as in Perl itself is e.g.

/foobar/i
/ foo bar /x    
/foobar.*/s

etc ?

Please explain correctly doing such on Nim
Thanks much in advance


Solution

  • I report the excellent answer provided by Hlaftaana to this same question on the forum: https://forum.nim-lang.org/t/8884

    With re you supply a set of RegexFlag arguments to the re function, with nre you supply them inside the regex.

    Example:

    import re
    let reg1 = re("foo bar", {reIgnoreCase, reExtended})
    # or
    import nre
    let reg2 = re"(?ix)foo bar"