Jump to content

Quick Q on StringRegExp


Wombat
 Share

Go to solution Solved by DW1,

Recommended Posts

Ok, so a quick question:

If I have a filepath: F:FolderFile.lst  OR F:FolderFolderFile.lst

and I wanted to extract information from it as such:  Array #1 = File.lst  & Array #2 = Folder(the folder name directly behind the backslash infront of the file)

How would i do this?

I'm trying to wrap my head around StrinRegExReplace but its a beast above my current level...

EDIT: Possibly a better explanation of what i need to extract is:

F:FolderFile.lst  OR F:FolderFolderFile.lst

$Foldername =

$Filename =

Edited by Wombat

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

Necessary Conditions

  • The Path should end up with a file-name having an extension.
  • There should be no "." periods in folder-name.
#include <Array.au3>

$sPath = "F:\Folder\File.xx"

$aRet = StringRegExp($sPath, "([^\\]*)\\([^\\.]*\..*$)", 3)
_ArrayDisplay($aRet)

There is an _PathSplit() func included with Autoit, it should help you.

Simultaneously if you search the forum you would get plently examples involved with _PathSplit and regex.

Regards :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Necessary Conditions

  • The Path should end up with a file-name having an extension.
  • There should be no "." periods in folder-name.
#include <Array.au3>

$sPath = "F:\Folder\File.xx"

$aRet = StringRegExp($sPath, "([^\\]*)\\([^\\.]*\..*$)", 3)
_ArrayDisplay($aRet)

There is an _PathSplit() func included with Autoit, it should help you.

Simultaneously if you search the forum you would get plently examples involved with _PathSplit and regex.

Regards :)

 

didn't even think along the lines of PathSplit()...

I was stuck in Array/String though process

Thanks PhoenixXL!

and thank you danwilli for the answer to the thread, I hope this helps others on the forum :)

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

 

The same as Phoenix' one but without conditions

#include <Array.au3>

$sPath = "F:\Fol.der1\Fol.der2\File"

$aRet = StringRegExp($sPath, "([^\\]*)\\([^\\]+?$)", 3)
_ArrayDisplay($aRet)

 

Excellent!

I really wish I understood StringRegExp... it hurts meh brain

Edited by Wombat

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

 

Then take care of your brain and use the traditional way :)

#include <Array.au3>

$sPath = "F:\Fol.der2\File"

$split = StringSplit($sPath, "\")
$n = $split[0]
$split[0] = $split[$n]
$split[1] = $split[$n-1]
Redim $split[2]
_ArrayDisplay($split)

 

Wow, so many options... its like a candy store! :dance:

Edited by Wombat

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...