Jump to content
Sign in to follow this  
DW1

RegEx help please :)

Recommended Posts

DW1

Hi guys, it's been a while since I have posted ;)

Work is keeping me too damn busy lol.

I need help getting a regular expression to work properly.

I have a file which contains data like:

Status : lable::somefunc() : "C:\Program Files\Common Files\something shared"
Status : lable2::otherfunc() : "string here", "C:\Program Files\Common Files\something shared"
SomeLable::datalogging::func(var) :  : Object did some thing C:\Program Files\Common Files\something shared\somedll.dll on thread 0x0000000A.

I need to strip the file path out. They are not all going to be on the C: drive.

The return I would be looking for would look like this:

Status : lable::somefunc() : "something shared"
Status : lable2::otherfunc() : "string here", "something shared"
SomeLable::datalogging::func(var) :  : Object did some thing somedll.dll on thread 0x0000000A.

Note that I will still need the last entry from the path. If it is a file, then I need to keep the file name, and if it is a directory, I need to keep the lowest directory name.

I would need to loose everything between the 'X:\' the last '/' for every path.

Thanks a lot guys ^_^

Share this post


Link to post
Share on other sites
Xenobiologist

$str = 'Status : lable::somefunc() : "C:\Program Files\Common Files\something shared"' & @CRLF & _
        'Status : lable2::otherfunc() : "string here", "C:\Program Files\Common Files\something shared"' & @CRLF & _
        'SomeLable::datalogging::func(var) :  : Object did some thing C:\Program Files\Common Files\something shared\somedll.dll on thread 0x0000000A.'

ConsoleWrite(StringRegExpReplace($str, '\w{1}:\\[a-zA-Z \\]+\\', '') & @CRLF)

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
DW1

Thanks Mega ^_^

Can you break that down for a noob? I am writing this for a console app that just does regex (project requirement) and that regex killed it haha. Probably just a difference in engines, so I need assistance breaking down the logic.

Share this post


Link to post
Share on other sites
Xenobiologist

Hi,

\w*:\\[a-zA-Z \\]+\\

\w* means drive letter which is optional (*) because could be \\...\...\ as a path

:

\\ means \

[a-zA-Z \\] all the signs which are possible in the path. You may add äöü or something.

\\ end with a \

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
DW1

Thanks so much Mega, what about the "+"

if I remove the "+\\" it will not crash the app, but will not be correct results because I modified it.

Share this post


Link to post
Share on other sites
Xenobiologist

Hi,

what crashed what?

Have a look at : http://www.autoitscript.com/autoit3/pcrepattern.html

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
DW1

Thanks Mega, I will be talking with the person who wrote our regex engine. I think there may be something wrong with it.

Your solution is elegant and works flawlessly. It is our engine that needs help.

You rock!

Regards,

DW

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.