Q:

extract part of the path to file or "/" if it doesn't exist

Okay guys 
here are my 2 strings 
D:/path/to/project/js/folder/LVL1/LVL2/mylibrary.js 
and 
D:/path/to/project/js/folder/mylibrary.js 
for the first I want to get /LVL1/LVL2 
and 
for the second i want to get a slash /
here is my regex ^.+js\/folder(\/[^\.]*[^\/])\/.+\.js+$ 
it works fine for the first but returns nothing for the second
this is to be used in an ant task (more specifically the jscomp). Basically I want to compile every javascript file in the 'D:/path/to/project/js/folder/' and put the output somewhere else with the nested folders. Here's an excerpt of my ant task if it ever helps.
<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>

Thanks

A:

you could use this pattern  
^.+js\/folder(\/|.*?)[^\/]+?\.js$  

Demo
^               # 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

