<p>Okay, so, thanks to <a href="https://craftcms.stackexchange.com/a/4398/654">carlcs' answer</a> I managed to solve the camel-case to lower-dash-case conversion. The other direction was a bit trickier, but again, after digging in a bit deeper I was able to figure it out myself:</p>

<p>First off, I'm not using the plugin any longer! Yay! The secret was to create a custom Twig filter that would convert dash-separated strings like so:</p>

<pre><code>{{ 'my-first-car'|dash2camel }}
{# outputs 'myFirstCar' #}
</code></pre>

<p>With the help of <a href="http://cameronspear.com/blog/craft-cms-twig-filter-extension/" rel="nofollow noreferrer">this guide</a> and some code from <a href="https://stackoverflow.com/a/12642156">this answer</a> I created my own custom Twig filter within Craft. Nothing fancy and hacked together quickly, but <strong>I've put it on <a href="https://github.com/rppld/dash2camel" rel="nofollow noreferrer">GitHub</a> if someone runs into the same issues</strong>.</p>

CC BY-SA 3.0
2014-11-04T15:48:15.377Z
2014-11-04T15:48:15.377Z
2017-05-23T12:38:53.957Z
rppld
<p>Can't help you with that <code>\e</code> modifier problem and my regex knowledge is very limited, but that camelCase problem can be solved with Twig filters:</p>

<pre><code>{{ 'camelCase'|replace('/([A-Z])/', '-\\1')|lower }}
</code></pre>

CC BY-SA 3.0
2014-10-28T11:05:14.470Z
2014-10-28T11:05:14.470Z
carlcs
<p>I'm relying on the <a href="https://github.com/low/low_regex" rel="nofollow noreferrer">Low Regex plugin</a> to convert section handles from camelCase to lower-dash-case to use them in URLs, like so:</p>

<pre><code>{section.handle|regex('/(^|[a-z])([A-Z])/e', 'strtolower(strlen("\\1") ? "\\1-\\2" : "\\2")',(section.handle))}
</code></pre>

<p>…and further, to convert the segment of the URL that contains the dash-separated section name to camel case, so I can work with it in my templates, like so:</p>

<pre><code>{% set sectionHandle = craft.request.getFirstSegment() %}
{% set sectionHandleCc = sectionHandle | regex('/-([a-z])/e', 'strtoupper(strlen("\\1") ? "\\1\\2" : "\\2")',(sectionHandle)) %}
{% set section = craft.sections.getSectionByHandle(sectionHandleCc) %}
</code></pre>

<p>Now, OS X 10.10 Yosemite ships with PHP version 5.5.14 pre-installed and as of 5.5.0 the e-modifier for regex patterns is <a href="http://php.net/manual/en/reference.pcre.pattern.modifiers.php#reference.pcre.pattern.modifiers.eval" rel="nofollow noreferrer">deprecated</a>, so on my local machine I get this error and the site breaks:</p>

<p><img src="https://i.sstatic.net/2fPIH.png" alt="enter image description here"></p>

<p>I got in touch with the plugin author and he suggested removing the e-modifier, which seemed to work within the templates, but when I removed the modifier in the sections entry URL format the CP wasn't able to re-save my entries and I couldn't save new entries either.</p>

<p><strong>The question that remains is</strong>: Is there a workaround using a different regex pattern or – and that would be my preferred scenario – is there an approach I didn't think of that allows me to omit the plugin dependency completely? I guess one option would be to keep the section handles all lowercase, but I'd like to have them dash-separated in the URLs.</p>

<url><sections><regex>
Workaround for deprecated regex pattern modifier in PHP 5.5.0 and up (10.10 Yosemite)
# Workaround for deprecated regex pattern modifier in PHP 5.5.0 and up (10.10 Yosemite)

(Asked by: username_0 on 2014-10-28)

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") ? "\\1-\\2" : "\\2")',(section.handle))}

…and further, to convert the segment of the URL that contains the dash-separated section name to camel case, so I can work with it in my templates, like so:
{% set sectionHandle = craft.request.getFirstSegment() %}
{% set sectionHandleCc = sectionHandle | regex('/-([a-z])/e', 'strtoupper(strlen("\\1") ? "\\1\\2" : "\\2")',(sectionHandle)) %}
{% set section = craft.sections.getSectionByHandle(sectionHandleCc) %}

Now, OS X 10.10 Yosemite ships with PHP version 5.5.14 pre-installed and as of 5.5.0 the e-modifier for regex patterns is deprecated, so on my local machine I get this error and the site breaks:

I got in touch with the plugin author and he suggested removing the e-modifier, which seemed to work within the templates, but when I removed the modifier in the sections entry URL format the CP wasn't able to re-save my entries and I couldn't save new entries either.
The question that remains is: Is there a workaround using a different regex pattern or – and that would be my preferred scenario – is there an approach I didn't think of that allows me to omit the plugin dependency completely? I guess one option would be to keep the section handles all lowercase, but I'd like to have them dash-separated in the URLs.

**Tags:** url, sections, regex

---

## 2 answers

### Answer by username_0 on 2014-11-04. Score: 2 | Accepted answer

Okay, so, thanks to carlcs' answer I managed to solve the camel-case to lower-dash-case conversion. The other direction was a bit trickier, but again, after digging in a bit deeper I was able to figure it out myself:
First off, I'm not using the plugin any longer! Yay! The secret was to create a custom Twig filter that would convert dash-separated strings like so:
{{ 'my-first-car'|dash2camel }}
{# outputs 'myFirstCar' #}

With the help of this guide and some code from this answer I created my own custom Twig filter within Craft. Nothing fancy and hacked together quickly, but I've put it on GitHub if someone runs into the same issues.


---

### Answer by username_1 on 2014-10-28. Score: 1

Can't help you with that \e modifier problem and my regex knowledge is very limited, but that camelCase problem can be solved with Twig filters:
{{ 'camelCase'|replace('/([A-Z])/', '-\\1')|lower }}


---

