Search code examples
regexintellij-ideasubstringvelocitylive-templates

Find and remove regex string in Velocity


I've created a Live Template with IntelliJ IDEA and I'm trying to find and remove a specific String within Velocity through a variable but failed

I tried to set $moduleName variable through $NAME variable -which is giving 'File name'- with RegExp.

I'm removing View string (part of File name) during creating JS file, but failed. Code:

## Input for 'File Name' is FooView**

#set($regex = '/(View)/') ## Try to get 'View' string with regex**
#set($checkRegex = $NAME.matches($regex)) ## Checks if regex finds**
#set($moduleName = $NAME.replaceAll($regex, '')) ## Try to remove 'View' string on $NAME variable**

## So the results;**
$checkRegex ## Returns as FALSE**
$moduleName ## Still returns all input as 'FooView'**

Solution

  • If you want to replace View, put it as is in regex:

    #set($regex = 'View')