What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » RegExp - exec

RegExp - exec
Author: Message:
davidpolitis
Full Member
***


Posts: 371
Reputation: 16
Joined: Aug 2006
O.P. RegExp - exec
I need some help with RegExp, for some reason the code bellow isn't working. Can someone please help me?

The code is basically meant to turn C:\David\eg.png to eg

code:
var re = new RegExp(".*\\(.*)\\.");
var FileBase = re.exec(MyString)[1];

It's simply just plain not working at all! :S

Thanks in advance,
David.
   

This post was edited on 08-22-2007 at 11:10 AM by davidpolitis.
08-22-2007 10:35 AM
Profile PM Find Quote Report
phalanxii
Full Member
***


Posts: 146
Reputation: 5
32 / Male / Flag
Joined: Aug 2006
Status: Away
RE: RegExp - exec
If you want a quick fix, try:
code:
var MyString = "C:\\David\\eg.png";
var re = /([^\/\\]*)\./;
var FileBase = re.exec(MyString)[1];
But just as an explanation, when you use the new RegExp("...") notation, your regular expression is taken from what it appears as a string. That means new RegExp("\\\\a\\\\") works the same as /\\a\\/, both of which capture a string which displays as \a\. My regular expression captures a group of letters that are not slashes up to a full-stop. Be aware that if there are no matches though, your script will have an error.
08-22-2007 11:14 AM
Profile PM Find Quote Report
davidpolitis
Full Member
***


Posts: 371
Reputation: 16
Joined: Aug 2006
O.P. RE: RegExp - exec
Mate, it won't go to the last dot after the last slash, it'll go to the first it runs into so it isn't help me much. Do you have any idea how to fix that?

Sorry if I didn't make that clear. I just gave an example, and I tried to say in my starting off sentence.

EDIT: dt helped me on IRC :P

code:
var re = /\\([^\\]*?)\.[^\.]*$/;
var FileBase = re.exec("C:\\David\\eg.png")[1];

This post was edited on 08-22-2007 at 11:28 AM by davidpolitis.
08-22-2007 11:21 AM
Profile PM Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1621
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: RegExp - exec
code:
if(/\\(.*)\.\w*$/.exec(MyString) !== null){
var FileBase = RegExp.$1;
}

If you are using the file using an ActiveXObject (The Scripting.FileSystemObject specifically) then you can just use .Name property.

This post was edited on 08-22-2007 at 11:30 AM by markee.
[Image: markee.png]
08-22-2007 11:29 AM
Profile PM Find Quote Report
davidpolitis
Full Member
***


Posts: 371
Reputation: 16
Joined: Aug 2006
O.P. RE: RE: RegExp - exec
quote:
Originally posted by markee
If you are using the file using an ActiveXObject (The Scripting.FileSystemObject specifically) then you can just use .Name property.

Now that you mention it... I never thought about that :(

Maybe someone else will find the code useful.

Anyway, thank you guys for all the support and help.
08-22-2007 11:33 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On