代码之家  ›  专栏  ›  技术社区  ›  Nuri Engin

查找并删除速度中的regex字符串

  •  1
  • Nuri Engin  · 技术社区  · 6 年前

    我已经创建了一个带有Intellij思想的实时模板,我正在尝试查找和删除一个特定的 String 在通过A的速度范围内 variable 但是失败了

    我试图设置 $moduleName 变量通过 $NAME 变量 -它给出了“文件名”- 具有 RegExp .

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

    ## 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 回复  |  直到 6 年前
        1
  •  1
  •   Ori Marko    6 年前

    如果要替换视图,请将其放置 在正则表达式中:

    #set($regex = 'View')