Jump to content

...


DirtDBaK
 Share

Recommended Posts

Not that i dont want to answer you'r question, but StringRegExp is a huge topic i recomend you search the net for a guide or book on this topic.

O'Reilly have written books on this, the pocket edition is great. oreilly store here

UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

Hi DBak,

I had the same problem when I first used this function... here is a sample

$var="TU T ------- I-I"

If Not IsArray(StringRegExp ( $var, "[[:alnum:]]" ,3)) Then ; No alphanumeric pattern found in string

MsgBox(0,@ScriptName,"This string is not alphanumeric !")

Else

MsgBox(0,@ScriptName,"This string is alphanumeric !")

EndIf

Now you can use other pattern type to test and do other action with the result ... I hope this will help.

Chris.

FreeRiderHonour & Fidelity

Link to comment
Share on other sites

Maybe if you post an example...

If I don't understand how to use it then how will I be able to provide you an example...

Mabye if you read ALL of my post you would know what I want it to do

But heres the only thing I can come up with

$String = 'GuiCreate("Test",800,600,34,23)'
MsgBox(0,'',TestString($String))
$String = 'GuiCreate("Test",800,600)'
MsgBox(0,'',TestString($String))

Func TestString($STR);tests to see if the sting has a valid autoit script format for command GuiCreate
If $STR <> correct syntax  ;NEED HELP TO DETERMINE THIS
Return 0
Else
Retrun an array with each parameter of the command
Endif
EndFunc

I guess that should be exactly what you want..??...

Seems pointless but oh well

[center][/center]

Link to comment
Share on other sites

Provide an example String:

$string = "Place your example test string here"

1. Tell us what you want to check for.

2. Tell us what you hope to gain from using the function.

3. Tell us what result you expect, or see #2.

Here's an example from Xenobiologist to get you going as to how you could do something with it:

#include<Array.au3>
  $string = "This is the example sentence I want to break down into chunks of say 3 words. Test"
  $re = StringRegExp($string, '((.*?\s+){3})|.*', 3)
  _ArrayDisplay($re)

As for filters, you combine them in a logical order usually:

Say I have a crazy string:

"My number [12] is really cool."

Using \w would produce "M"

Using \w+ would produce "My number "

Using \w+\[ would produce "My number ["

Using \[\d+.*\] would produce "[12]"

\w = Match any "word" character: a-z, A-Z or underscore (_). Only applies to a "single" character.

\w+ = Match any "word" character: a-z, A-Z or underscore (_). Applies to multiple characters

\[ = match the [ specifically.

\d = Match any digit (0-9). Only applies to a "single" digit.

\d+ = Match any digit (0-9). Applies to multiple digits.

.* = All.. until...

So \w+\[ simply means Find any word characters that appears up to and including an open [ bracket.

\w+\s would mean Find any word characters that appear up to and including any whitespace.

These are basic rudimentary examples and they serve only as tiny examples. And I'm sure there are better ways to check against a string, or rather better filters to use. Again, just giving you a rough idea of the syntax.

You simply combine the filtering, understand how the groups work together when combined, play around a little bit and you'll get the hang of it.

Edited by Ealric

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Link to comment
Share on other sites

1. Tell us what you want to check for.

2. Tell us what you hope to gain from using the function.

3. Tell us what result you expect, or see #2.

1.) I want it to check for proper syntax of the autoit function GuiCreate()

2.) I want to gain either a true or false if it has proper syntax and haveing the paramerters would be nice to

3.) I was hoping it would work like my code above, but I will post it again:

$String = 'GuiCreate("Test",800,600,34,23)'

MsgBox(0,'',TestString($String))

$String = 'GuiCreate("Test",800,600)'

MsgBox(0,'',TestString($String))

Func TestString($STR);tests to see if the sting has a valid autoit script format for command GuiCreate

If $STR <> correct syntax ;NEED HELP TO DETERMINE THIS

Return 0

Else

Retrun an array with each parameter of the command

Endif

EndFunc

[center][/center]

Link to comment
Share on other sites

  • Moderators

You'd probably do better to see how the Au3Check does it (if it hasn't been re-written)... Anyway it was interesting all the same (If you are doing every function... though it will be tedious, I believe I came up with a simple way of controlling the good with the bad:

#include <array.au3>
$String = 'GuiCreate("Test",800,600,34,23)'
$aP = _ParamValidation($String)
_ArrayDisplay($aP, "Parameters")

Func _ParamValidation($sString)
    ;List of functions you are testing
    Local $aIndex[2] = ["", "GUICreate"]
    ;Total Params
    Local $aTotal[2] = ["", 8]
    ;Mandatory Params: n = Mandatory
    Local $aMandatory[2] = ["", 1];Put number of mandatory params, put 0 if no mandatory
    
    ;Seperate the function name
    Local $aFunc = StringRegExp($sString, "^\s*(\w+)\s*\(", 1)
    ;If no function name, return error code 1
    If IsArray($aFunc) = 0 Then Return SetError(1, 0, "")
    
    ;Find our function and dimension number for $aTotal/$aMandatory
    Local $nDimension = 0
    For $iCC = 1 To UBound($aIndex) -1
        If StringRegExp($sString, "(?i)^\s*" & $aIndex[$iCC] & "\s*\(") Then
            $nDimension = $iCC
            ExitLoop
        EndIf
    Next
    
    ;Put all parameters in a single string for parsing later
    Local $aParams = StringRegExp($sString, $aFunc[0] & "\s*\(\s*(.+?)\)" , 3)
    ;If the array failed, the function was written and passed wrong more than likely, return error code 2
    If IsArray($aParams) = 0 Then Return SetError(2, 0, "")
        
    ;Check if parameter is blank and if is allowed to be blank if it is
    If $nDimension <> 0 And ($aParams[0] = "" Or $aParams[0] = '""' Or $aParams[0] = "''") Then
        ;If the parameter is blank and not allowed to be, return error code 3
        If $aMandatory[$nDimension] Then Return SetError(3, 0, "")
    EndIf
    
    
    Local $aParamBreakDown = StringRegExp($aParams[0], '"(.*?)"\s*(?m:$|,)|\s*(.+?)\s*(?m:$|,)', 3)
    ;Fill return array with parameters from param break down
    Local $aReturnParams[(UBound($aParamBreakDown) / 2) + 2]
    For $iCC = 0 To UBound($aParamBreakDown) - 1 Step 2
        $aReturnParams[($iCC / 2) + 1] = $aParamBreakDown[$iCC]
    Next
    $aReturnParams[0] = UBound($aReturnParams) - 1

    ;If the total params are greater than the total allowed, then return error code 4 and extended number of params
    If $aReturnParams[0] > $aTotal[$nDimension] Then Return SetError(4, $aReturnParams[0], "")

    Return $aReturnParams
EndFunc
You could get a lot more in depth with if the parameter should be a string/integer/float/long etc... but this is just proof of concept all the same.

In the future... since you know all the "string" functions other than RegExp, it would be much more efficient (since it seems people are having an issue with understanding what you are trying to do), to write the concept out in the functions you know and understand and maybe ask someone if they wouldn't mind converting it, rather than having some write the whole function themselves and them ask them to take their time and write comments so you can better understand what they did with the time they took for you.

Edit:

Had a message box in there I needed to remove.

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

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...