Jump to content

StringRegExp Help


 Share

Recommended Posts

The helpfile Explanation of StringRegExp needs a little more info, I think. I'm having extreme difficulty understanding the example.

Specifically, If you do an ArrayDisplay after the function is called (As I have done in the below code) The array is empty, yet the array is put through a placeholder Variable, and all of a sudden, values appear? Where do the values that appear in the message box latter on come from?

;Option 4, global return, php/preg_match_all() style
$array = StringRegExp('F1oF2oF3o', '(F.o)*?', 4)
_ArrayDisplay($Array,"View 1") ; <---- Added Line
for $i = 0 to UBound($array) - 1
$match = $array[$i]
    for $j = 0 to UBound($match) - 1
        msgbox(0, "cRegExp Test with Option 4 - " & $i & ',' & $j, $match[$j])
    Next
Next

And what does it mean to have it "Return an array of arrays containing global matches including the full match" Versus "Return array of matches including the full match?" how does the 'global' affect the outcome? I'm trying to work with the examples, but each time I try, I get an even less-expected result, and that just confuses me even more.

Thanks,

Paulie

Edited by Paulie
Link to comment
Share on other sites

Each element of $array is an array..

example:

$avNewArray = $array[$i]
_ArrayDisplay($avNewArray)
Edited by RazerM
My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

The helpfile Explanation of StringRegExp needs a little more info, I think. I'm having extreme difficulty understanding the example.

Specifically, If you do an ArrayDisplay after the function is called (As I have done in the below code) The array is empty, yet the array is put through a placeholder Variable, and all of a sudden, values appear? Where do the values that appear in the message box latter on come from?

;Option 4, global return, php/preg_match_all() style
$array = StringRegExp('F1oF2oF3o', '(F.o)*?', 4)
_ArrayDisplay($Array,View 1) ; <---- Added Line
for $i = 0 to UBound($array) - 1
$match = $array[$i]
    for $j = 0 to UBound($match) - 1
        msgbox(0, "cRegExp Test with Option 4 - " & $i & ',' & $j, $match[$j])
    Next
Next

And what does it mean to have it "Return an array of arrays containing global matches including the full match" Versus "Return array of matches including the full match?" how does the 'global' affect the outcome? I'm trying to work with the examples, but each time I try, I get an even less-expected result, and that just confuses me even more.

Thanks,

Paulie

Have you tried the link given in the help file for a fuller description?

Global matches are matches found throughout the string to search as compared to the first match found.

I know very little about StringREgExp., but I use a program called V-Grep which is freeware and very useful for finding text in files. This program has a regexp tester which consists of two edit boxes. You enter a string in one and the search pattern in the other and see what happens. Something like that could be useful for learning about StringREgExp and I expect there are lots of similar products.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • Moderators

The helpfile Explanation of StringRegExp needs a little more info, I think. I'm having extreme difficulty understanding the example.

Specifically, If you do an ArrayDisplay after the function is called (As I have done in the below code) The array is empty, yet the array is put through a placeholder Variable, and all of a sudden, values appear? Where do the values that appear in the message box latter on come from?

;Option 4, global return, php/preg_match_all() style
$array = StringRegExp('F1oF2oF3o', '(F.o)*?', 4)
_ArrayDisplay($Array,View 1) ; <---- Added Line
for $i = 0 to UBound($array) - 1
$match = $array[$i]
    for $j = 0 to UBound($match) - 1
        msgbox(0, "cRegExp Test with Option 4 - " & $i & ',' & $j, $match[$j])
    Next
Next

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Alright, Thanks alot for the help, However, with the new information, I tried to Map the results of a Flag=4 StringRegExp into a 2D array (instead of an Array-In-Array) which would be mighty convenient to have happen in the first place.

Here is my example:

#include <Array.au3>
$array = StringRegExp('F1oF2oF3oF4o', '(F.o)*?', 4)
;Find Biggest Sized "$Match" Array
Dim $Big[UBound($array)]
for $i = 0 to UBound($array) - 1
$match = $array[$i]
$Big[$i] = Ubound($match)
Next
$MatchBound = _ArrayMax($Big)
;Set size of new array to accommodate biggest array
Dim $NewArray[UBound($array)][$MatchBound]
For $x = 0 to UBound($array)-1
    $match = $array[$x] 
        ReDim $Match[$MatchBound+1];Resize the second dimension to be equal to the biggest (because some were smaller for some reason)
    For $y = 0 to $MatchBound-1
        $NewArray[$x][$y] = $Match[$y]
    Next
Next
_ArrayDisplay($NewArray)

Thanks Again,

Paulie :)

Link to comment
Share on other sites

  • Moderators

You're making it move to the other chars past your point... there are no other chars before a match is found, so a blank char is given:

$array = StringRegExp('F1oF2oF3oF4o', '(F.o)', 4)
;Find Biggest Sized "$Match" Array
Dim $Big[UBound($array)]
for $i = 0 to UBound($array) - 1
$match = $array[$i]
$Big[$i] = Ubound($match)
Next
$MatchBound = _ArrayMax($Big)
;Set size of new array to accommodate biggest array
Dim $NewArray[UBound($array)][$MatchBound]
For $x = 0 to UBound($array)-1
    $match = $array[$x] 
        ReDim $Match[$MatchBound+1];Resize the second dimension to be equal to the biggest (because some were smaller for some reason)
    For $y = 0 to $MatchBound-1
        $NewArray[$x][$y] = $Match[$y]
    Next
Next
_ArrayDisplay($NewArray)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You're making it move to the other chars past your point... there are no other chars before a match is found, so a blank char is given:

Oh... I see.... :thinking: Well, then, If thats the case, then why does the helpfile use an example which doesn't use the most suitable pattern for the string?

I was deeply confused when i ran this... (Straight from the help)

$array = StringRegExp('F1oF2oF3o', '(F.o)*?', 4)
for $i = 0 to UBound($array) - 1
$match = $array[$i]
    for $j = 0 to UBound($match) - 1
        msgbox(0, "cRegExp Test with Option 4 - " & $i & ',' & $j, $match[$j])
    Next
NextoÝ÷ Ø    ÝZV§Ë méíëêÞ²ém·zØ^©è¶«nV§Ø^§b}÷«z{kzË¥¶Ü"qç­qëZ«y«&jH§Ø^±©r§ëh¶Å©©æ¬Ê¦i×­¢l¬r¸©¶·¦¢÷­ê®¢Ú®¢Ü!Èey«Þ²g°Øm+ºÚ"µÍÌÍØ^HHÝ[ÔYÑ^
    ÌÎNÑ[ÑÑÛÉÌÎNË ÌÎNÊÊIÌÎNË
NÐÚ[ÙY[BÜ   ÌÍÚHHÈPÝ[
    ÌÍØ^JHHBÌÍÛX]ÚH  ÌÍØ^VÉÌÍÚWBÜ    ÌÍÚHÈPÝ[
    ÌÍÛX]Ú
HHBÙØÞ
    ][ÝØÔYÑ^ÝÚ]Ü[Û
H   ][ÝÈ  [È ÌÍÚH [È ÌÎNË ÌÎNÈ [È ÌÍÚ  ÌÍÛX]ÚÉÌÍÚJB^^

I simply get each result twice. (Though I still don't understand why an Array-In-Array is needed when the information could just as easily be expressed in a 1D array.)

Edited by Paulie
Link to comment
Share on other sites

  • Moderators

Don't rely on the helpfile for RegExp's. Download RegExCoach to test your patterns, and use the perl site I gave you the link to to learn more.

Jon has admitted that with his time being limited, he is waiting for one of us to update the help file on RegExp's.

Edit:

Paulie, admittingly, I use only "no flag" / "1" / or "3", I've never found a need for any other.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

@Paulie - Thanks for asking the great question, see all the great answers you've gotten! Good stuff indeed!

2. $match = $array[$i] ... $match is just a Variable, not an array, you then check it assuming it is an array... as I "think" that is what razerm was pointing out.

@SmOke_N' - before reading this tread and your message I thought the same thing about $match being an array. In fact when I added _ArrayDisplay($match) it showed the information. What lead me to believe $match was actually an array was the for $j = 0 to UBound($match) - 1 (see below). Then again I could be wrong about $match being a 1d array. Also thanks for the links, man I'd love to see your bookmarks in your browser. No telling what other gems you have in there just collecting dust!

$match = $array[$i]
    for $j = 0 to UBound($match) - 1
        msgbox(0, "cRegExp Test with Option 4 - " & $i & ',' & $j, $match[$j])
    Next
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...