String matching with variable interpolation

Hi,

I have the following:

field = "out"
match(r"<out>\s*(.*?)\s*</out>",<out>hello</out>)

But I would like to replace the “out” in <out>\s*(.*?)\s*</out> by field to make it dynamic.
How can i do that?

Thank you

In general you should not use Regex to handle HTML (XML) since Regex cannot parse HTML.

for this specif use:

julia> field = "out"
"out"

julia> rg = "<$field>\\s*(.*?)\\s*</$field>"
"<out>\\s*(.*?)\\s*</out>"

julia> match(Regex(rg), "<out>hello</out>")
RegexMatch("<out>hello</out>", 1="hello")
2 Likes

Thank you. The XML that I am trying to parse is in a weird format. I tried to use LightXML and EzXML but for this specific xml file it is not working.