473,394 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to write the following regexp?

hello,

I have the problem writing the regular expression to verify the valid
system path in the way that RegExp.$1 has to contain path up to the
parent folder of a file, and RegExp.$2 should contain a file name (or be
empty if there was no file in the path). The allowed characters are all
except \ / : * ? " < > | The problem I have is to find a smart way to
separate the file part from the rest of the path.. could you give me
some hints or maybe someone has similar solution in his arhive and could
share it?

thanks for help, would appreciate any hlp..
regards,
geos
Jul 23 '05 #1
1 1197
geos wrote:
I have the problem writing the regular expression to verify the valid
system path in the way that RegExp.$1 has to contain path up to the
parent folder of a file, and RegExp.$2 should contain a file name (or be
empty if there was no file in the path). The allowed characters are all
except \ / : * ? " < > | The problem I have is to find a smart way to
separate the file part from the rest of the path.


If you problem is just separating the two parts, then you can do this
with or without a regular expression

function foo(fullName){
var pos=Math.max(
fullName.lastIndexOf("\/"),
fullName.lastIndexOf("\\")
);
return {
$1:fullName.substr(0,pos),
$2:fullName.substr(pos+1)
};
}

function bar(fullName) {
return new RegExp(
"^(.*)[\\\/]([^\\/:*?\"<>|]+)$"
).exec(fullName), RegExp;
}

If your problem has to do with validating the format, you could use a
filesystem object directly, that would also permit to assert the
existence of the folders/files?
HTH,
Yep.
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jon Maz | last post by:
Hi, I have written a page to test a function of mine that strips non-English accents and various other characters out of a given string. The function itself (called 'StripAll' in the code below)...
0
by: Chris Croughton | last post by:
I'm trying to use the EXSLT regexp package from http://www.exslt.org/regexp/functions/match/index.html (specifically the match function) with the libxml xltproc (which supports EXSLT), but...
4
by: Jon Maz | last post by:
Hi All, I want to strip the accents off characters in a string so that, for example, the (Spanish) word "práctico" comes out as "practico" - but ignoring case, so that "PRÁCTICO" comes out as...
4
by: Jon Maz | last post by:
Hi All, I want to strip the accents off characters in a string so that, for example, the (Spanish) word "práctico" comes out as "practico" - but ignoring case, so that "PRÁCTICO" comes out as...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.