Search code examples
regextemplatestoolkit

regex to get string between slash's


Im using template toolkit, but I believe the regexp works the same as js.

given a string, for e.g: /home/views/register/success or /home/views/register.tt

how do I get the string after (and including) 'views/' upto the next '/' or '.', giving me in this case 'views/register'

something like:

var template_name = template.name.match('views/'+REGEXP);

Solution

  • (views/[^./]*) should do the trick.

    I'm not sure if you need to escape the dot. If the abore regex doesn't work try adding a backslash before the dot.