Hi Darren,

Glad that's useful.  FYI, I was trying to get you an answer using the `&&`
Conjunction method as well, but fell short because you want to filter out
certain literal words (i.e. negation). That's why I simplified your regex
pattern to `<wb> <alpha>+ <wb>`.  I trust you know your specifications.

Another approach might be good old `grep`, for which there two different
negation forms described in the Docs:

https://docs.raku.org/routine/grep

~ % raku -ne 'BEGIN my regex K { null | false | true }; put
.words.grep(none / <K> /);'  cats_dogs_jays.txt
cat
dog
jay
cat
dog
jay
~ % raku -ne 'BEGIN my regex K { null | false | true }; put .words.grep(
{!/ <K> /} );'  cats_dogs_jays.txt
cat
dog
jay
cat
dog
jay
~ % raku -ne 'BEGIN my regex K { null | false | true }; put .words.grep(
{!/ <K> /} ).grep(/ <[A..Z]> /);'  cats_dogs_jays.txt






~ % raku -ne 'BEGIN my regex K { null | false | true }; put .words.grep(
{!/ <K> /} ).grep(/ <[a..z]> /);'  cats_dogs_jays.txt
cat
dog
jay
cat
dog
jay

HTH, Bill.

On Sun, Jul 30, 2023 at 9:48 PM Darren Duncan <dar...@darrenduncan.net>
wrote:

> Thank you William, that boolean condition check option looks like it is in
> the
> direction of the answer I sought.
>
> FYI, the reason I spelled out the character class explicitly rather than
> using
> "<alpha>" was because I wanted it strictly applied to ASCII chars and not
> everything Unicode considers a char, and this seemed the best way to be
> sure.
>
> -- Darren Duncan
>
> On 2023-07-30 9:30 p.m., William Michels via perl6-users wrote:
> > Hi Darren (and Marcel),
> >
> > Two different approaches:
> > https://docs.raku.org/language/regexes#Conjunction:_&&;
> > <https://docs.raku.org/language/regexes#Conjunction:_&&;>
> >
> >  From the docs:
> > /"For example if you have a regex quoted that matches a quoted string,
> then `/
> > <quoted> && <-[x]>* /` matches a quoted string that does not contain the
> > character `x`."/
> >
> > Second approach :
> >
> https://stackoverflow.com/questions/64909029/is-it-possible-to-do-boolean-assertions-with-raku-regex
> > https://docs.raku.org/language/regexes#Regex_Boolean_condition_check
> >
> > Testing "Regex Boolean condition check" with a one-liner:
> >
> > ~ % cat  cats_dogs_jays.txt
> > cat
> > dog
> > jay
> > null cat
> > false dog
> > true jay
> > ~ % raku -ne 'put $/ if $_ ~~ m:g/ ( <wb> <alpha>+ <wb> ) <!{ $0 eq
> "null" |
> > "false" | "true" }> /;'  cats_dogs_jays.txt
> > cat
> > dog
> > jay
> > cat
> > dog
> > jay
> >
> >
> > HTH, Bill.
> >
> >
> >
> >> On Jul 30, 2023, at 08:59, Marcel Timmerman wrote:
> >>
> >> On 30-07-2023 06:21, Darren Duncan wrote:
> >>> Hello, I have a Raku regex question.
> >>>
> >>> See the following:
> >>>
> >>>     token nonquoted_alphanumeric_text
> >>>     {
> >>>         <!before [null | false | true] <wb>>
> >>>         <[ A..Z _ a..z ]> <[ 0..9 A..Z _ a..z ]>*
> >>>     }
> >>>
> >>> What I want is for "nonquoted_alphanumeric_text" to match any simple
> ASCII
> >>> bareword EXCEPT a few special cases indicated in the example.
> >>>
> >>> I was hoping there might be some better way of specifying this than my
> example.
> >>>
> >>> Is there any more direct way in Raku to say, match this pattern
> initially,
> >>> but if the result equals these exceptional values then treat it as
> having not
> >>> matched.
> >>>
> >>> I am looking for a fully declarative solution in the grammar itself,
> not
> >>> something involving post-processing.
> >>>
> >>> Thank you.
> >>>
> >>> -- Darren Duncan
> >>>
> >> You can try: <|wb><ALPHA><ALNUM>*
>
>

Reply via email to