On Sat, Jan 17, 2009 at 12:01 PM, Kairit Sirts <[email protected]> wrote:
> I'm trying to find those segments from the text, which come immediately
> after '=' and end with any other non-character. In a string 'koge=ne#ma=tu'
> I'd like to find 'ne' and 'tu'.

I think I would do that like this:

require'strings'
alpha=:(,toupper)'abcdefghijklmnopqrstuvwxyz'
class=:0"0 a.
class=:1 (a.i.'=')} class
class=:2 (a.i.alpha)} class

state=:0 10#:10*".;._2]0 :0
  0   1.1 0  NB. initial state: wait for =
  0.2 1.2 1  NB. after =: accept text
)

fsm=: }.each@((0;state;class)&;:)

If I moved that }.each logic inside the states,
I could never get empty words in my result.

However, note that I am not able to reproduce your problem.

If I use your state machine (but swapping the = and alpha
character class indices to match my arbitrary choice:

state=:0 10#:10*".;._2]0 :0
  0   1    0
  0   0    2.1
  0.5 1.5  2
)

fsmc=: (0;state;class)&;:


   fsmc  'koge=ne#ma=tu'
+--------+
|ne#ma=tu|
+--------+

Have I made a mistake?

Thanks,

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to