Actually, that's buggy.

I should have said:

   mid=. (,:({:-{.@,,0:)M) rxcut 1{::segs

Oops...

-- 
Raul


On Sat, Aug 30, 2014 at 4:13 AM, Raul Miller <[email protected]> wrote:
> J has "PCRE" regular expressions:
>
>    require 'regex'
>    url=: 'http://www.jsoftware.com/help/pcre/pcrepattern.html'
>    >('http://[^/]+'&rxmatch rxcut ]) url
>
> http://www.jsoftware.com
> /help/pcre/pcrepattern.html
>
> Now.. regular expressions seem like they ought to be a natural fit for
> J - if nothing else, the sort of people who turn up their nose at J
> syntax are probably either (a) so inured to regular expressions that
> they forget how they look, or (b) can't stand regular expressions.
>
> That said... PCRE stands for "perl compatible regular expressions" and
> J is missing a significant feature from perl's implementation: string
> interpolation.
>
> Perl has a string language where you can specify variables to plug
> into the string, and PCRE ties into that mechanism. J is significantly
> more verbose for this kind of thing.
>
> In other words, in perl, I could do this:
>   $url=~ s{http://([^/]+)}{https://$1/wiki};
>
> and if $url were the value of url, above (in perl scalar variable
> names begin with $ and strings are treated as scalars - perl does not
> have J's concept of rank and instead approximates it with the rank
> indicator hard-coded into the variable name), then the above sentence
> would modify its value to be:
>
> https://www.jsoftware.com/wiki/help/pcre/pcrepattern.html
>
> Here's some equivalent (explicit) J:
>
>   if. {:,M=. 'http://([^/]+)' rxmatch url do.
>     segs=. M rxcut url
>     mid=. (,:({:-{.@{.)M) rxcut 1{::segs
>     url=. ;}.(<'https://',(1{::mid),'/wiki') 1} segs
>   end.
>
> As you can see, it's a bit more complex.
>
> So ...
>
> I'm not going to tackle writing such a thing - at least, not tonight.
> But that's something that might be nice - support for a string
> interpolation language, including tie-in support for the jregex
> locale.
>
> (I am mostly writing this to organize my thoughts - as you can see,
> this topic is messy enough in J that organizing thoughts is probably a
> good idea.)
>
> (And, yes, this particular task could be accomplished more easily in J
> - my actual task is more complicated and needs a more involved regular
> expression. I'm just outlining what I see as an issue.)
>
> Thanks,
>
> --
> Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to