Questions tagged [regex]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
15 votes
2 answers

How can I perform a RegEx match in Twig?

Is it possible to perform a RegEx match on a string in Twig? I'm looking for something like this: {% set string = "This is **string**. **wer** qewr **234**" %} {% set match = string.matches(/([*][*...
  • 2,372
5 votes
1 answer

Double escaping Regular Expressions in Craft's Twig replace filter?

Just trying to use Craft's Twig replace filter to remove number prefixes from the beginning of User Groups names and I have had to double escape the character classes etc to get it to work. I tried ...
4 votes
2 answers

Regex to remove trailing slash not working

I am trying to remove the http:// and trailing slash from a string, so my replace filter looks like this: website|replace({ 'http://': '', '/\\/$/': '' }) The http:// part works, the trailing slash ...
  • 674
2 votes
1 answer

Route that should be matching numbers not matching a zero?

I have the following in my routes.php file: return array( 'articles/(?P<sectionId>\d+)/(?P<offset>\d+)' => 'articles/index' ); And while localhost/articles/4/1, for example, ...
1 vote
1 answer

Element API - UrlHelper generates backwards slashes (regex)

I am generating a url within Element API: 'profile' => UrlHelper::getUrl("directory/company/{$member->id}/{$urlslug}"), which outputs: http:\/\/craft.fira\/directory\/company\/1501\/abet-...