regex.e find_all
- Posted by jessedavis Mar 26, 2010
- 825 views
The find_all() function in regex is supposed to return an atom >0< if there are no matching sub strings; however, it returns an empty sequence. I suppose that this doesn't really matter as you can test for the length of the sequence; however, the test > if atom(Obj) where Obj is an object returned by find_all() should be TRUE if find_all returned an atom. The test is always FALSE no matter what find_all discovers. here is the code -------------------------->
#!/home/jd/euphoria/bin/eui -- euphoria 4.0 running on ubuntu 9 include std/pretty.e include std/regex.e as re sequence str_1,str_2 object b,c integer fn = open("/home/jd/euphoria/jd_src/test_regex.dat","r") str_1 = "<property name=\"title\" translatable=\"yes\">My Window</property>" str_2 = "<property name=\"title\" translatable=\"yes\">My Window/property>" |missing '<' re:regex r2 = re:new(">[a-zA-Z0-9 ]+<") b = re:find(r2,str_1) c = re:find(r2,str_2) ? b ? c b = re:find_all(r2,str_1) c = re:find_all(r2,str_2) ? b ? c
here is the output ------>
~/euphoria/jd_src>./reg_test.ex { {42,52} <---find() finds one! } -1 <---find() finds none note atom returned { { {42,52} <---find_all() finds one! } } {} <---find_all() finds none and returns an empty sequence -------end output
Consistency is a good thing..