Questions tagged [regex]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
19 views

Retour Regex to insert a new directory

I'm building out a new site and have moved all the existing client asset upload directories into one parent directory. old site: /hero/ /books/ /slider/ new site: /uploads/hero/ /uploads/books/ ...
0
votes
1answer
28 views

RegEx Redirects for Legacy URLs

My legacy URLs have this structure: /teachings/tag/13721/omnipotent/ or /teachings/series/17764/fearless/ For both the tag and the series they are always followed by a string of digits and then slug ...
1
vote
1answer
16 views

Default Users Password Regex

Assume a front end registration form. I would like to validate user passwords before posting to the server. I have not been able to find the default password requirements as of yet for craft 3. Could ...
1
vote
1answer
37 views

Replace throwing Unknown Modifier Error

I've tested the regex and seems to work perfectly, but when placing it within Craft it seems to throw the following error: preg_replace(): Unknown modifier '/' {% set ig = user.instagram|raw|...
1
vote
1answer
28 views

RexEg Pattern to Exclude Using the Retour Plugin

The Retour plugin has this setting: Exclude Patterns - Regular expressions to match URLs that should be excluded from Retour. How would I exclude images (jpg and png) from being handled by Retour? My ...
1
vote
1answer
40 views

Routing: How can I ignore a parameter in route definition?

I'm trying to route users to a "locations" structure entry that normally has a URL structure that looks like: locations/<slug> My client wants to use the structure of links from their old site ...
1
vote
1answer
82 views

Craft 3 RegEx problem

I am trying to change all rgb colours in a bit of text/content. I have the RegEx working here in php using preg_replace: preg_replace("/#[a-zA-Z0-9]{6}|rgb\((?:\s*\d+\s*,){2}\s*[\d]+\)|rgba\((\s*\d+\...
1
vote
1answer
183 views

striptags but leave link test in between

I have a rich text (redactor field) that I'm using striptags on to remove the html markup from the front end. However I noticed for links it whips out the link and the text in between. Is this ...
1
vote
1answer
100 views

|replace filter is matching too many characters

I'm looking to format out image tags from a string using the |replace filter. The behavior I'm looking for is to give it a string like this: <img src="test.jpg"><p>some text</p><...
3
votes
1answer
3k views

Twig replace regex

As I understand, craft overrides Twig's replace filter to allow for the use of regex; which is just running preg_replace under the hood When running the following regex through preg_replace in a php ...
2
votes
2answers
350 views

Using a back reference inside a regex search string within replace filter

I’m trying to insert a programmatically generated id attribute into child elements of parsedown processed text. I'm aware that Craft’s twig replace filter incorporates preg_replace, so… I have a ...
7
votes
1answer
466 views

Does Craft / Twig support regex groups?

I see Craft does support regex in replace search. But there is no info on using regex groups, ie string | replace('/this is a (string)/', 'This is another $1'). Is this feature implemented? If so - ...
1
vote
1answer
118 views

Possible to use REGEX Backreference in Routes

I've searched and searched for info on regex backreferences in Craft's route.php file to no avail. I have a URL structure required by the client along the lines of: / [state] / [section] / region / ...
1
vote
1answer
93 views

Using 'replace' with a regex is throwing an error. Any ideas why?

I am attempting to strip out <p> tags around <img> tags that are automatically getting generated in a WYSIWYG field. The error: preg_replace(): Unknown modifier '&gt;' {{ story.html|...
1
vote
1answer
130 views

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-...
3
votes
1answer
2k views

How do I create an advanced route with multiple slugs?

I'm trying to create a route for an RSS feed which allows for the following routes. domain/feed domain/category/feed domain/category/subcategory/feed I have the first two routes working and the ...
4
votes
2answers
3k views

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 ...
2
votes
1answer
387 views

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
1answer
203 views

How to redirect a url with a query to one that does not have a query

I'm using Redirect Manager (https://github.com/rkingon/Craft-Plugin--Redirect-Manager) and I"m trying to redirect: www.website.com/?post_type=testimonials To: www.website.com/about-us I've tried the ...
2
votes
1answer
3k views

Use regex in replace filter

any idea why this: %20AND%20foo%3A%22(.+?)%22 won't match this: %20AND%20foo%3A%22some random string of characters%22 in the Twig |replace filter? If i do this: {% set foo = '%20AND%20foo%3A%22some ...
1
vote
2answers
202 views

Workaround for deprecated regex pattern modifier in PHP 5.5.0 and up (10.10 Yosemite)

I'm relying on the Low Regex plugin to convert section handles from camelCase to lower-dash-case to use them in URLs, like so: {section.handle|regex('/(^|[a-z])([A-Z])/e', 'strtolower(strlen("\\1") ? ...
3
votes
1answer
2k views

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
2answers
553 views

Can I use Regex in the Find and Replace tool?

Does the Find and Replace tool support regex? I need to remove a certain section of an image url for all images in the 'field_body' column. So if I had an image referenced as such http://craft.dev/...
13
votes
2answers
35k views

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(/([*][*...