Re: regex

[email protected] (Levi Elias Nystad-Johansen via beginners) Mon, 22 Jan 2024 20:32:52 +0000
Newsgroups perl.beginners
Message-ID <vkH8wlLY2lVAIpsSc9_szwcf3kq0NIGjsKoigc9j7YYvdFh-CTythN7DmNJU7tv623svpu728SorQuXY3kgXDJAUD-uFYIYYBiZOut5lUDw=@protonmail.com>
I agree that this is confusing, and I think many resources describing regex in unhelpful ways is partly to blame.
descriptions like "pattern that matches against a string" and similar.

this implies that a regex has to match the string, but this is not the case.
a regex does not have to match the string, instead the string has to satisfy the regex.

"aaa" satisfies /a{,2}/ because it contains everything the regex requires.
thinking of regex in this way has been a help to me atleast 😊

-L

-------- Original Message --------
On 22. jan. 2024, 13:23, Jorge Almeida wrote:

> Please help me to understand this:
> $ perl -e 'exit(10) if "aaa"=~/a{,2}/;'
> $ echo $?
> $ 10
>
> Thanks
>
> Jorge Almeida