在Velocity中查找并删除正则表达式字符串

时间:2018-07-25 10:18:06

标签: regex intellij-idea substring velocity live-templates

我已经使用IntelliJ IDEA创建了一个实时模板,并且试图通过String在Velocity中查找并删除特定的variable,但失败了

我尝试通过$moduleName变量设置$NAME变量,该变量给出了RegExp的“文件名”-

我在创建JS文件时删除了View字符串(文件名的一部分),但是失败了。代码:

## 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'**

1 个答案:

答案 0 :(得分:1)

如果要替换View,请在正则表达式中按原样放置

#set($regex = 'View')