好的家伙
这是我的2个字符串
D:/path/to/project/js/folder/LVL1/LVL2/mylibrary.js
和
D:/path/to/project/js/folder/mylibrary.js
首先我要获得/LVL1/LVL2
和
对于第二个我想得到一个斜杠/
这是我的正则表达式^.+js\/folder(\/[^\.]*[^\/])\/.+\.js+$
它适用于第一个
但没有返回第二个这将用于ant任务(更具体地说是jscomp
)。基本上我想编译'D:/ path / to / project / js / folder /'中的每个javascript文件,并将输出放在嵌套文件夹的其他位置。如果有任何帮助,这里是我的蚂蚁任务的摘录。
<target name="compileJS" description="minifier les fichier JS">
<taskdef name="jscomp"
classname="com.google.javascript.jscomp.ant.CompileTask"
classpath="${lib.dir}/thirdparty/closure-compiler/compiler.jar" />
<taskdef resource="net/sf/antcontrib/cpptasks/antlib.xml">
<classpath>
<pathelement location="${lib.dir}/thirdparty/ant-contrib/cpptasks.jar" />
</classpath>
</taskdef>
<echo message="Searching for files in ${basedir}\charte\js" />
<for param="filename">
<path>
<fileset dir="${basedir}/charte/js">
</fileset>
</path>
<sequential id="i">
<!-- This gets the filename without the directory path. -->
<basename property="file.@{filename}" file="@{filename}" />
<propertyregex property="file"
input="@{filename}"
regexp="\\"
replace="/"
override="true"
defaultvalue="@{filename}" />
<echo message=">...>...> input = ${file}"/>
<propertyregex property="directory.@{filename}"
input="${file}"
regexp="^.+js\/folder(\/[^\.]*[^\/])\/.+[\.js]+$"
select="\1"
casesensitive="false" override="true" />
<echo message=">...>...> directory = ${directory.@{filename}}"/>
<echo message="Compressing file ${file.@{filename}} in ${directory.@{filename}}" />
<jscomp compilationLevel="simple"
output="${build.dir}/charte/js/directory.@{filename}/${file.@{filename}}">
<sources dir="${base.dir}/charte/js/directory.@{filename}/">
<file name="${file.@{filename}}" />
</sources>
</jscomp>
</sequential>
</for>
</target>
由于
答案 0 :(得分:0)
你可以使用这种模式
^.+js\/folder(\/|.*?)[^\/]+?\.js$
^ # Start of string/line
. # Any character except line break
+ # (one or more)(greedy)
js # "js"
\/ # "/"
folder # "folder"
( # Capturing Group (1)
\/ # "/"
| # OR
. # Any character except line break
*? # (zero or more)(lazy)
) # End of # Capturing Group (1)
[^\/] # Character not in [^\/]
+? # (one or more)(lazy)
\. # "."
js$ # End of string/line
答案 1 :(得分:0)