regex_replace working right??

Started by handsource-dyko, March 09, 2012, 02:45:32 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

handsource-dyko

During my documentation of mod_regex I made an example for regex_replace. I doesn't seem to give the desired output. I tested this regular expression here to verify the behaviour: http://www.regular-expressions.info/javascriptexample.html.

Type into the Regexp field: cat
Type into the Subject string field: it's raining cat's and dogs
Click test match and show match
Type into the Replacement text field: bird
Click on the replace button

The result should be: it's raining bird's and dogs

However, this is not result I get with my test program. It outputs only the word "bird" as result.
Have I missed something?



The example program is here:


// import modules
IMPORT "mod_say";
IMPORT "mod_debug";
IMPORT "mod_regex";


GLOBAL


   string sourcetext="It's raining cat's and dogs."; // the orginal sentence
   string searchtext="cat";                          // the search string
   string replacetext="bird";                        // the replacement string
   
   string replace_result;
   
   int result;
   
   
PROCESS main();

BEGIN


   // first, look for "cat".
   result=regex(searchtext,sourcetext);
   say("");
   say(searchtext+" found at position: "+result);

   
   say("");
   say("orginal text: "+sourcetext);

   // replace "cat" with "bird".
   replace_result=regex_replace(searchtext,sourcetext,replacetext);
   say("");
   say("replace_result: "+replace_result);
 
END


SplinterGU

bad arguments

try this

   replace_result=regex_replace(searchtext,replacetext,sourcetext);
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

handsource-dyko

ok! :) I fixed it. I might have been confused.