> Wish I had a Q[;;;] expression inside a regex

You can put any Raku code that produces a string
into a regex by using the syntax `$(code)`.

So this displays `True`:

```
say so Q[ <foo></foo> / ;;; ^&%%$$ ] ~~ / $( Q[ <foo></foo> / ;;; ^&%%$$ ] ) /
```
as does:
```
my $string = Q[ <foo></foo> / ;;; ^&%%$$ ];
say so $string ~~ / $( $string ) /;
```

----

> when does regex NOT start reading at the
> beginning of the input data stream?

Never. It *always* starts at the beginning of the input.

> Why does it need the ^

You use `^` when you want a pattern to be *anchored*
to the start, so that if it fails at the start then that's it.

To understand this, consider an example.

Let's say you have an input string 'foo'.

An `/ oo /` regex will match, because it doesn't contain an
anchor, so the pattern is free to match *anywhere* in the
input string. That is, while it *fails* to match *at the start*,
because an 'o' does *not* match an 'f', *it keeps going*,
and then succeeds when *the next* two input characters
*do* match.

In contrast, `/ ^oo /` will *not* match, because the `^`
"anchors" the match to the *start* of the input string, i.e.
immediately before the 'f' in 'foo', and the first 'o' in `^oo`
does *not* match the 'f', and given that the match is
*anchored* to the start, if it fails at the start, it gives up.

----

I've no idea what was causing your hang, but fwiw it
doesn't make sense to me that it happened due to a
zero length input or an undefined variable.

----

love, raiph

Reply via email to