我已经使用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'**
答案 0 :(得分:1)
如果要替换View,请在正则表达式中按原样放置 :
#set($regex = 'View')