1. regex.e find_all
- Posted by jessedavis Mar 26, 2010
- 826 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..
2. Re: regex.e find_all
- Posted by jessedavis Mar 26, 2010
- 874 views
there is an easy fix for this problem. It's not elegant but add one line of code (next to the last line below) to the function find_all() in regex.e--->
public function find_all(regex re, sequence haystack, integer from=1, object options=DEFAULT) if sequence(options) then options = or_all(options) end if object result sequence results = {} while sequence(result) with entry do results = append(results, result) from = max(result) + 1 if from > length(haystack) then exit end if entry result = find(re, haystack, from, options) end while if length(results) then return results else return -1 end if end function
3. Re: regex.e find_all
- Posted by jessedavis Mar 27, 2010
- 784 views
Ignore my last post. There is a more complete answer to this and another question in a later post. Subject: regex.e find_all another problem Regards, jd