Re: Problem with find_replace
- Posted by _tom (admin) Oct 30, 2014
- 1025 views
include std/regex.e as re include std/console.e regex re_inlineCommands = re:new("<.*?<") sequence currentline = "here is some <bold<text> and some <italic<text> and <cmd 1, cm2, cmd3<multiple> and <bold<text>.\n" sequence inlineCommands = re:all_matches(re_inlineCommands, currentline) console:display( inlineCommands ) --{ -- { -- "<bold<" -- }, -- { -- "<italic<" -- }, -- { -- "<cmd 1, cm2, cmd3<" -- }, -- { -- "<bold<" -- } --} for i = 1 to length(inlineCommands) do regex r = re:new(inlineCommands[i][1]) currentline = find_replace(r, currentline, "<b>") end for puts(1, currentline) -- here is some <b>text> and some <b>text> and <b>multiple> and <b>text>.
You have a small indexing error.
_tom