Non greedy regex match

filchristou
Thu, 06 Jul 2023 16:08:17 +0000
General Usage

How can I match non-greedily a regex in julia ?

A general stackoverflow post mentions .*? but it doesn’t work.

Julia docs point to pcre2 site that mentions (?U) default ungreedy (lazy) but I am not sure how to use it.

Example

julia> str = """GML GraphML""";

julia> reg = r"";

julia> match(reg, str)
RegexMatch("GML ", 1="Zamren.gml\">GML <a href=\"files/Zamren")

The matching result should be RegexMatch("", 1="Zamren")

PS

Please don’t suggest custom workarounds like:

julia> match(r"]*)\.graphml\">", str)
RegexMatch("", 1="Zamren")

5 posts - 3 participants