-
-
Save iNamik/4147047 to your computer and use it in GitHub Desktop.
This gist is working like a charm!! Thank ya for sharing
Thanks ! That means a lot for code I created in 2017 :)
The current regexp doesn't account for trailing or leading whitespace in the string. Eg. {{ foo }}
will require an input of [' foo ' => 'bar']
in order to work - We needed an implementation that allows for that without causing issues.
A regexp that accounts for that could look like the following: '/{{\s*([^{}]+\S)\s*}}/'
-> https://regex101.com/r/4ts83c/1
I'd also recommend using mb_strtolower
if possible, if you have even the slightest chance of encountering multibyte characters (æ, ø, å, ü etc) when lower casing.
Great code otherwise! Thanks!
@ExeQue wrote:
A regexp that accounts for that could look like the following:
'/{{\s*([^{}]+\S)\s*}}/'
-> https://regex101.com/r/4ts83c/1
Thanks for the suggestion - I've updated the regex but with a slightly different take - My update doesn't expect or allow \s
to exist in the tag name.
I'd also recommend using
mb_strtolower
if possible, if you have even the slightest chance of encountering multibyte characters (æ, ø, å, ü etc) when lower casing.
Thats good advice, but I think there's a general consensus that the mb_
functions are slower, so I decided to just add a comment for the user to decide if the change makes sense for their use case.
Great code otherwise! Thanks!
Thanks! Its fun to see this gist still getting used so long after I created it !
This gist is working like a charm!! Thank ya for sharing