Sign in to follow this  
Followers 0
Simucal

Stringregexpreplace

7 posts in this topic

#1 ·  Posted (edited)

Ok.. so I'm starting to get a basic hang on stringregexp's.

However, I have a situation where my StringRegExp will sometimes produce one word for an array entry and sometimes two.

Example:

[0] = "Sunny"

[1] = "Partly Cloudy"

[2] = "Rainfall"

[3] = "Very cloudy"

Is the result of my StringRegExp:

$DescArray = StringRegExp($10DayFile, '(?:"padding:0px 3px 0px 0px;">)([a-zA-Z]*\s?[a-zA-Z]*?)(?:</TD>)',3)

This all works great. However, what I would LIKE to do is: For whatever entries have two words, replace the space that seperates them with an @CRLF.

StringRegExpReplace ( "test", "pattern", "replace", [ count ])

I've thought about doing a StringRegExpReplace, but I'm a little hazy on how I would setup up the "replace" field of the function.

I think I will need to use \1-\9 to insert my matched group.

StringRegExpReplace($10DayFile, '(?:"padding:0px 3px 0px 0px;">)([a-zA-Z]*\s?[a-zA-Z]*?)(?:</TD>)',StringReplace(\2," ",@CRLF),0)

However, StringReplace will not take the \2 to refer to the second matched group. I'd like to stick with StringRegReplace/StringReg's and not do any combersome loops.

Thanks,

-Sim

EDIT: As a work around.. I StringReplace each member of the array.. but I wanted to see how else it could be done.

Edited by 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



$DescArray = StringRegExp($10DayFile, '(?:"padding:0px 3px 0px 0px;">)([a-zA-Z]*\s?[a-zA-Z]*?)(?:</TD>)',3)

StringRegExpReplace($10DayFile, '(?:"padding:0px 3px 0px 0px;">)([a-zA-Z]*)\s?([a-zA-Z]*?)(?:</TD>)',',0)

You can try this:

StringRegExp(StringRegExpReplace($10DayFile, '(?:"padding:0px 3px 0px 0px;">)([a-zA-Z]*)\s?([a-zA-Z]*?)(?:</TD>)', '\1' & @CRLF & '\2', 0), '(?:"padding:0px 3px 0px 0px;">)([a-zA-Z]\r\n[a-zA-Z]*?)(?:</TD>)',3)

Untested... could you post the file you are trying to parse?


[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

This may be a dumb question: but why not do this?

$string = "Rainfall"

$check = StringSplit ( $string , " " )
If $check[0] = 2 Then
    MsgBox(0, "", $check[1] & @CRLF & $check[2])
Else
    MsgBox(0, "", $string)
EndIf


$string = "Very cloudy"

$check = StringSplit ( $string , " " )
If $check[0] = 2 Then
    MsgBox(0, "", $check[1] & @CRLF & $check[2])
Else
    MsgBox(0, "", $string)
EndIf

$string = "Very cloudy indeed"

$check = StringSplit ( $string , " " )
If $check[0] = 2 Then
    MsgBox(0, "", $check[1] & @CRLF & $check[2])
Else
    MsgBox(0, "", $string)
EndIf

[edit] The code makes a lot more sence now

Edited by Manadar

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Because I would need to do that for each member of the array and it is clunky.

If I can do it with one stringregexpreplace, then it is a better solution.

I'm already doing a:

StringReplace($DescArray[0], " ", @CRLF)
Edited by 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

Ah, having the source to parse makes it alot easier, here's the one-liner version, returns an array:

#include <array.au3>
$ret = StringRegExp(StringRegExpReplace($10DayFile, '(?:"padding:0px 3px 0px 0px;">)([a-zA-Z]*)\s*?([a-zA-Z]*?)(?:</TD>)', '~~\1' & @CRLF & '\2~~', 0), '~~(.*?)~~',3)
_ArrayDisplay($ret, "")

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

The previous one didn't handle one word descriptions, this one does:

#include <Array.au3>
$ret = StringRegExp(StringRegExpReplace($10DayFile, '(?:"padding:0px 3px 0px 0px;">)([a-zA-Z]*?)(?:\s*?)([a-zA-Z]*?)(?:</TD>)', '~~\1' & @CRLF & '\2~~', 0), '~~(.*?)~~|"padding:0px 3px 0px 0px;">(.*?)</TD>',3)
_ArrayDisplay($ret, "")

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

Wow Neogia, you went above and beyond what I expected. That is exactly what im looking for!!

Many thanks! Also, I'll be looking for the update on your StringRegExp tutorial.

-Sim


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