Jump to content

StringRegExpReplace, cant get pattern right


Recommended Posts

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)
Link to comment
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

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

Link to comment
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.

Link to comment
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)
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...