I get a different result from what you got, which suggests you had
changed your regexp, perhaps to something like this:

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

Ah... I now see that your followup has an updated pattern...

---------------

Anyways, what I don't understand is what you meant by:

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

Do you mean that you want to replace matched digit sequences in that
text with some sort of representation of their offsets?

Or are you intending something else?

Thanks,

-- 
Raul

On Thu, Apr 11, 2019 at 1:01 PM Nimp O <[email protected]> wrote:
>
> 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to