Hello everyone,
Here is a minimal working example of what I'm trying to accomplish:

load'regex'
pat =: '\( (\d)\,(\d)\s+(\d)\,(\d)\s+\)'

test=: 0 : 0

a

    ( 2,3

      4,5 )

c

    ( 10,11

      12,13 )

)


So using the regex pattern I was able to extract the numbers from this string. 
Each subgroup correspond to a single number.


]mat=: ((pat;,1+i.4) rxmatches test) rxfrom test
+--+--+--+--+
|2 |3 |4 |5 |
+--+--+--+--+
|10|11|12|13|
+--+--+--+--+

Suppose I changed this matrix such as in:

]new =: >:&.".&.> mat

+--+--+--+--+

|3 |4 |5 |6 |

+--+--+--+--+

|11|12|13|14|

+--+--+--+--+


How can I merge this result back to the variable test.


I tried applying the function directly using rxapply but it only replaced the 
first match.


(pat;,1+i.4) >:&.". rxapply test
a

( 3,3

4,5 )

c

( 11,11

12,13 )

And also tried using rxmerge but got the following error:

new ( (pat;,1+i.4) rxmatches test) rxmerge test

|length error: rxcut_jregex_

| 'beg len' =.|:,.x

Does anyone know how to extend these functions for dealing with multiple 
subgroups of matching terms? For me the merge case is more important since it 
allows different transformations on each group.
Thanks.





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

Reply via email to