From: Jim Freeze Date: 2003-04-14T23:56:45+09:00 Subject: Re: How do I call a regex from C? On Monday, 14 April 2003 at 23:25:03 +0900, ts wrote: > >>>>> "J" == Jim Freeze writes: > > J> If I use rb_funcall, Do I have to make two calls? One > J> to create the regex and one to apply it? > J> Is there a faster way? > > It really depend what call you want to do. > > For example, String#sub can take a String or a Regexp as the first > argument. You can call Regexp::new (via rb_funcall) > > To create a regexp you have also rb_reg_regcomp(VALUE). You can use > perhaps also rb_reg_match() > > > Guy Decoux Ok, this is what I have done so far: static VALUE re_equal; in_some_init_func() { re_equal = rb_reg_regcomp("\\s*=\\s"); re_space = rb_reg_regcomp("\\s+"); } in_main_loop() { VALUE sp = rb_str_new2(" "); // I don't think this is allowed -------v rb_funcall(line, "gsub!", 2, re_equal, "=") // should probably be this. rb_funcall(line, "gsub!", 2, re_equal, sp) } If I just want to replace with a character, is there a faster way than to create a string object? What if I want to replace with an empty string ""? Thanks -- Jim Freeze ---------- HOW YOU CAN TELL THAT IT'S GOING TO BE A ROTTEN DAY: #32: You call your answering service and they've never heard of you.