1. Problem with find_replace

Hi all,

I remember stumbling upon Euphoria almost 10 years ago while in college. Just stumbled upon it again trying to find a language to port a Perl prototype to.

I'm having a hard time with find_replace(). I am trying to cycle through a sequence which contains the substrings I want to replace, and use them as regular expressions. But the following code fails on

r = re:new(inlineCommands[i]) 

and not sure what it is I'm doing wrong.

regex re_inlineCommands = re:new("<.*?<") 
regex r 
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) 
 
for i = 1 to length(inlineCommands) do 
    r = re:new(inlineCommands[i]) 
    currentline = find_replace(r, currentline, "<b>") 
end for                             
 
puts(1, currentline)   

Any pointers from experienced Euphorians would be greatly appreciated.

regards,

yves

new topic     » topic index » view message » categorize

2. Re: Problem with find_replace

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: Problem with find_replace

Thanks so much Tom...works like a charm!

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu