Yes? E. is faster than rxmatches precisely because it is less powerful.
And note that you could also use ;: (but the trace operation is 5x larger than you need and most people don't like making state machines). -- Raul On Sun, Aug 16, 2015 at 2:09 AM, Jon Hough <[email protected]> wrote: > I recently went through the regex lab, and would like to know whether it is > more idiomatic for J users to use regex when matching simple patterns in a > string, or to use E. and similar verbs? > For example. If I have an (imaginary) DNA sequence string: > DNA=: > 'CGATTGACTAGTCGATTGCTGATGCTCTAGTCGTGATGCTATACTAGTGCGTCGATGCTAGCGCTAGTCGCATTTGA' > I want to find where 'CTAG' sequences exist in this string. Using regex, > 'CTAG' rxmatches DNA > will give the 5 indices where the CTAG pattern is found. > But I could equally do, > I. 'CTAG' E. DNA > which will give me the same indices. And it seems the non-regex way is more > efficient (in time and space): > > timespacex '( I. ''CTAG'' E. DNA)' > > > gives 1.5e_5 3008 > > > > > timespacex '( ''CTAG'' rxmatches DNA)' > > > gives 0.001103 6720 > > > Granted, the regex expression is as simple as possible. and regex can do more > complicated matching than E. can do, and possibly rxmatches gains efficiency > over E. for very longer DNA strings. But it seems for simple matches E. is > the better choice. > > > > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
