Last active
December 19, 2023 13:25
-
-
Save SpacePossum/b71821aab939438e654ebc9fc1714bd8 to your computer and use it in GitHub Desktop.
Example how Twig `(not) matches` works
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set foo = '123' %} | |
{{ foo matches '/^[\\d]+$/' ? 'Y' : 'N' }} | |
{{ foo matches not '/^[\\d]+$/' ? 'Y' : 'N' }} {# wrong, does not work! #} | |
{{ not (foo matches '/^[\\d]+$/') ? 'Y' : 'N' }} | |
{% set foo = 'abc' %} | |
{{ foo matches '/^[\\d]+$/' ? 'Y' : 'N' }} | |
{{ foo matches not '/^[\\d]+$/' ? 'Y' : 'N' }} {# wrong, does not work! #} | |
{{ not (foo matches '/^[\\d]+$/') ? 'Y' : 'N' }} | |
Y | |
N | |
N | |
N | |
N | |
Y |
Nice! Thanks!
Awesome - thanks for sharing this, it helped me today :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! :)