Live template using regular expression

I'm trying to figure out how to create a live template using the regularExpression() function but I'm not understanding how it works.

I have the string "LGR 0000-0003-4830-3302" and I want to transform it into "<p>LGR <ext-link ext-link-type="uri">0000-0003-4830-3302</ext-link></p>"

My template text: <p>$TEXT$</p>$END$

Now, when I edit the variables like this:

regularExpression(TEXT, "([A-Z]+) (.*?)", "$1 <ext-link ext-link-type=\"uri\">$2</ext-link>") the results is <p></p> without nothing! 

BUT if I change TEXT by clipboard() it works but the results is almost what I want: <p>LGR <ext-link ext-link-type="uri"></ext-link>0000-0003-4830-3302</p>, the second group ($2) is not placed where I want it to be and it's inserted at the end of the line, why?

What am I missing? Why this only works with clipboard?

0

You can't use the current template variable in the variable expression, only other variables that have been already defined can be used there. For a template like $FOO$ $BAR$ you can refer to FOO in $BAR$ expression only, but not in $FOO$ expression. In regularExpression(TEXT, "([A-Z]+) (.*?)", "$1 <ext-link ext-link-type=\"uri\">$2</ext-link>") TEXT is undefined.

 

0

请先登录再写评论。