Sign in to follow this  
Followers 0
Simucal

StringRegExpReplace, cant get pattern right

4 posts in this topic

One day.. in the not too distant future, I will be a master of all that is Regular Expression. Until that day, I still need some help from time to time :D

In this example script:

$s_Test = "*c:\Program Files\Adobe Bla\sinister\subpage.html*c:\autoit\test.txt*d:\music\pixes - where is my mind.mp3*c:\Program Files\AutoIt\*"
$s_FileList = StringRegExpReplace($s_Test, "\*.*?\\Program Files\\.*?\*", "*")
ConsoleWrite($s_FileList&@CRLF)

I have written a RegExpReplace to get rid of any of the filepaths that contain "\Program Files\" in them (and replace the whole filepath with a single '*').

So, lets say I had the string above: "*c:\Program Files\Adobe Bla\sinister\subpage.html*c:\autoit\test.txt*d:\music\pixes - where is my mind.mp3*c:\Program Files\AutoIt\*"

I would like it to end up as: *c:\autoit\test.txt*d:\music\pixes - where is my mind.mp3*" because neither of those entries have the "Program Files" in them. Its important that I use StringRegExpReplace and not any other method, for speed purposes. This list is several thousand entries long.

Anyone willing to take a stab at whats wrong with my pattern?

-Simucal


AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites



Problem ist that the last part

"*d:\music\pixes - where is my mind.mp3*c:\Program Files\AutoIt\*"

is converted to a single * because your pattern searches for:

- an Asterisk

- followed by any amount of any characters

- followed by \Program Files

- ....

So I'd suggest to search for

- an Asterisk

- followed by any amount of any Characters which are not an Asterisk:

$s_Test = "*c:\Program Files\Adobe Bla\sinister\subpage.html*c:\autoit\test.txt*d:\music\pixes - where is my mind.mp3*c:\Program Files\AutoIt\*"
$s_FileList = StringRegExpReplace($s_Test, "\*[^*]*?\\Program Files\\.*?\*", "*")
ConsoleWrite($s_FileList&@CRLF)

Of course, you could simply use StringSplit ($s_test,"*") instead :D

hope this helps,

Marc


It's my job to comfort the disturbed and to disturb the comfortable.
My Projects: Profiler, MakeSFX, UserInfo

Share this post


Link to post
Share on other sites

One day.. in the not too distant future, I will be a master of all that is Regular Expression. Until that day, I still need some help from time to time :D

In this example script:

$s_Test = "*c:\Program Files\Adobe Bla\sinister\subpage.html*c:\autoit\test.txt*d:\music\pixes - where is my mind.mp3*c:\Program Files\AutoIt\*"
$s_FileList = StringRegExpReplace($s_Test, "\*.*?\\Program Files\\.*?\*", "*")
ConsoleWrite($s_FileList&@CRLF)

I have written a RegExpReplace to get rid of any of the filepaths that contain "\Program Files\" in them (and replace the whole filepath with a single '*').

So, lets say I had the string above: "*c:\Program Files\Adobe Bla\sinister\subpage.html*c:\autoit\test.txt*d:\music\pixes - where is my mind.mp3*c:\Program Files\AutoIt\*"

I would like it to end up as: *c:\autoit\test.txt*d:\music\pixes - where is my mind.mp3*" because neither of those entries have the "Program Files" in them. Its important that I use StringRegExpReplace and not any other method, for speed purposes. This list is several thousand entries long.

Anyone willing to take a stab at whats wrong with my pattern?

-Simucal

Try this:

dim $result

$s_Test = "*c:\Program Files\Adobe Bla\sinister\subpage.html*c:\autoit\test.txt*d:\music\pixes - where is my mind.mp3*c:\Program Files\AutoIt\*"
$array = StringSplit($s_Test, "*")

For $i = 1 To $array[0] Step 1
    If StringInStr($array[$i], "Program Files" ) = 0 And $array[$i] <> "" Then $result = $result & "*" & $array[$i] 
Next
$result = $result & "*"

ConsoleWrite($result & @CRLF)

It's not the best but the easiest for newbie.

Share this post


Link to post
Share on other sites

Try this:

dim $result

$s_Test = "*c:\Program Files\Adobe Bla\sinister\subpage.html*c:\autoit\test.txt*d:\music\pixes - where is my mind.mp3*c:\Program Files\AutoIt\*"
$array = StringSplit($s_Test, "*")

For $i = 1 To $array[0] Step 1
    If StringInStr($array[$i], "Program Files" ) = 0 And $array[$i] <> "" Then $result = $result & "*" & $array[$i] 
Next
$result = $result & "*"

ConsoleWrite($result & @CRLF)

It's not the best but the easiest for newbie.

Yea, I have had that earlier, but it's slowness is prohibitive. That is why I said it must be StringRegExpReplace. I'll try and work on the pattern a little.

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

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  
Followers 0