Regex help...
Thierry Douez
th.douez at gmail.com
Mon Jun 5 09:59:39 EDT 2017
@Paul,
to defend you, it's not always so obvious to know what we can or cannot do
with regex.
@Mike
yes, Perl is great and that's certainly why I have embeded Perl in
LiveCode, Mmm, more than 10 years ago.
I've also helped some well known LiveCoders to do some complex
transformation with Perl where
they were lost in pure LiveCode script; but this is another story.
By the way, there is a not free LiveCode library called sunnYrex which
accepts LiveCode script inside
the replacement text.. pretty cool too but not useful in Paul use case.
Kind regards,
Thierry
2017-06-05 15:23 GMT+02:00 Paul Dupuis via use-livecode <
use-livecode at lists.runrev.com>:
> Thank you Thierry and everyone else.
>
> I should have realized that I couldn't do this entirely with regex due
> to the need to compare the number values. It was a long day yesterday
> and my brain just wasn't in full gear.
>
> -- Paul
>
>
> On 6/5/2017 4:06 AM, Thierry Douez via use-livecode wrote:
> > Hi Paul,
> >
> >
> > AFAIK you need to deal with an hybrid approach (regex + livecode)
> >
> > So, here is one way to do it:
> >
> >
> > put 3 into pPage
> >
> > repeat for each line T in tCiCData
> >
> > if matchText( T, "(?x) \t (\d+) , \d+ , (\d+) , \d+ \z", n1, n2)
> > then
> >
> > if (n1 <= pPage) and (n2 >= pPage) then
> >
> > put T & cr after tCiCfilteredData
> >
> > end if
> >
> > end if
> >
> > end repeat
> >
> > put tCiCfilteredData
> >
> >
> > But for the curious with an open-mind here is another solution:
> >
> >
> > get "perl -ne 'print if /\t(\d+),\d+,(\d+),\d+$(?(?{$1>PP ||
> > $2<PP})(*FAIL))/'"
> >
> > get replaceText( IT, "PP", pPage)
> >
> > put shell( IT && "/your/path/CiCData.txt")
> >
> > What? the regex do the comparison!
> > Well yes and no; in Perl we can embed Perl code *inside* the regex,
> > like: (?{$1>PP || $2<PP})
> >
> > $1>PP || $2<PP is a Perl expression.
> >
> > As we have a mixture of a regex pattern and some perl code;
> > that is in fact another hybrid solution.
> >
> >
> > And of course, you can do it using only chunks , item and so on...
> >
> > Have fun,
> >
> > Thierry
> >
> >
> > 2017-06-04 17:35 GMT+02:00 Paul Dupuis via use-livecode <
> > use-livecode at lists.runrev.com>:
> >
> >> I have a tab and cr delimited table of data, a sample line of which is
> >> below:
> >>
> >> 1<tab>Test<tab>4052,12594<tab>1,4052,3,2388<cr>
> >>
> >> Can someone help me revise this regex to match what I need?
> >>
> >> Thank you kindly, in advance.
> >>
>
--
------------------------------------------------
Thierry Douez - sunny-tdz.com
sunnYrex - sunnYtext2speech - sunnYperl - sunnYmidi - sunnYmage
More information about the use-livecode
mailing list