Sign in to follow this  
Followers 0
peethebee

RegExp for Windows Explorer Dir name?

15 posts in this topic

Hi!

I'm developping at the moment a fully AutoIt-driven Calendar application.

Who's interested (it is German and not yet ready at all, but GUI and surrounding functions are already there): http://autoit.aufwaerts.de/thread.php?threadid=596&sid=

Now my problem:

I would like to advance in my AutoIt abilities by using Regular Expressions for checking correctness of user input. I often read the help file and tutorials and sutff, but I just do not get it to work :D .

I need a piece of code that returns 1 if the String to parse does ONLY contain A-Z, a-z, -, _, or spaces.

Would be very nice if some RegExpKing could help me!

peethebee


vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvGerman Forums: http://www.autoit.deGerman Help File: http://autoit.de/hilfe vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

Share this post


Link to post
Share on other sites



Hi again,

I tried again for more than two hours this night. But it just does not work.

Anybody a hint for me please?

peethebee


vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvGerman Forums: http://www.autoit.deGerman Help File: http://autoit.de/hilfe vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

Share this post


Link to post
Share on other sites

Hi again,

I tried again for more than two hours this night. But it just does not work.

Anybody a hint for me please?

peethebee

How about posting the code you have so far, just for this function? You'll get more input that way.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Hi!

Of course I know that, PsaltyDS ;-) I'm goofing around long enough in this and my own forum ;-)

The problem is that the whole script is 1380 lines long and the Regex I had did not work at all.

Nevertheless a piece of code, which shows the overall situation I want to use the Regex in.

While 1
        $new_cal_name = InputBox("Kalendername", "Bitte geben Sie den Namen des neuen Kalenders an:", "NeuerKalender1")
        If $new_cal_name = 1 Then ; Abbrechen geklickt
            _SetStatus("Abgebrochen.")
            Return
        Else ; String checken!!!!!!!!
            $regexp_result = StringRegExp($new_cal_name, '[\w\d- ]{1,}', 1)
            If 1 Then
                ; richtig
                ExitLoop
            Else
                ContinueLoop
            EndIf
        EndIf
    WEnd
    
    ; Ordner anlegen
    DirCreate(@ScriptDir & "\Calendars\" & $new_cal_name)

I know that in this case there are easier ways to do it without RegExp but I want to learn it at an easy example because I will need it in harded cases.

Thank you,

peethebee


vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvGerman Forums: http://www.autoit.deGerman Help File: http://autoit.de/hilfe vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hi!

Of course I know that, PsaltyDS ;-) I'm goofing around long enough in this and my own forum ;-)

The problem is that the whole script is 1380 lines long and the Regex I had did not work at all.

Nevertheless a piece of code, which shows the overall situation I want to use the Regex in.

While 1
        $new_cal_name = InputBox("Kalendername", "Bitte geben Sie den Namen des neuen Kalenders an:", "NeuerKalender1")
        If $new_cal_name = 1 Then ; Abbrechen geklickt
            _SetStatus("Abgebrochen.")
            Return
        Else ; String checken!!!!!!!!
            $regexp_result = StringRegExp($new_cal_name, '[\w\d- ]{1,}', 1)
            If 1 Then
                ; richtig
                ExitLoop
            Else
                ContinueLoop
            EndIf
        EndIf
    WEnd
    
    ; Ordner anlegen
    DirCreate(@ScriptDir & "\Calendars\" & $new_cal_name)
 oÝ÷ Ø'£ajا¶¬q«¶«yªÞy«"z¼ÊËhv­Â+a¢ëQz1¥»­#§¶Ú%yªçÖ­jw³'±jjey·jë#¥wv+b«uçjǬN§*.¥ç­æÞ{ú®¢×»-²×©jX­¶W槺h©×²'«¶ÞiÖ§uìiz¸¦z{h«­¢+Ø)±½°ÀÌØí¹Ý}±}¹µ)]¡¥±Ä(ÀÌØíIÑÕɹô}QÍÑ%¹ÁÕÐ ¤(%5Í  ½à ØЬİÅÕ½ÐíIáÀQÍÐÅÕ½Ðì°ÅÕ½ÐìÀÌØíIÑÕɹôÅÕ½ÐìµÀìÀÌØíIÑÕɹµÀìÅÕ½Ðì°ÀÌØí¹Ý}±}¹µôÅÕ½ÐìµÀìÀÌØí¹Ý}±}¹µ¤±ÐìÐìÄQ¡¸á¥Ð)]¹((ì´´´´´´´´´´´´´´´´´´´´´´´´´´´´´(ì}QÍÑ%¹ÁÕÐ ÀÌØíÍ%¹ÁФ(ìIÑÕɸĽÈÙ±¥¥¹ÁÕÐÍÑÉ¥¹°À½È¥¹Ù±¥(ì´´´´´´´´´´´´´´´´´´´´´´´´´´´´´)Õ¹}QÍÑ%¹ÁÕÐ ÀÌØíÍ%¹ÁФ(]¡¥±Ä(ÀÌØí¹Ý}±}¹µô%¹ÁÕÑ ½à ÅÕ½Ðí-±¹É¹µÅÕ½Ðì°ÅÕ½Ðí    ¥ÑѸM¥¸9µ¸Ì¹Õ¸-±¹É̸èÅÕ½Ðì°ÅÕ½Ðí9ÕÉ-±¹ÈÄÅÕ½Ðì¤(%ÀÌØí¹Ý}±}¹µôÄQ¡¸ìÉ¡¸­±¥­Ð(ì}MÑMÑÑÕÌ ÅÕ½Ðíɽ¡¸¸ÅÕ½Ðì¤(IÑÕɸÀ(±ÍìMÑÉ¥¹¡­¸ÌÌìÌÌìÌÌìÌÌìÌÌìÌÌìÌÌìÌÌì(ÀÌØíÉáÁ}ÉÍÕ±ÐôMÑÉ¥¹IáÀ ÀÌØí¹Ý}±}¹µ°ÌäílÀäÈíÜÀäÈí´uìıôÌäì°Ä¤(%ÀÌØíÉáÁ}ÉÍÕ±ÐôÄQ¡¸(ìÉ¥¡Ñ¥(á¥Ñ1½½À(±Í(
½¹Ñ¥¹Õ1½½À(¹%(¹%(]¹(IÑÕɸÄ)¹Õ¹ìôôôÐí}QÍÑ%¹ÁÕÐ

Done this way, you can test it with various inputs until it works the way you want, without creating stray directories for now. I didn't understand "If 1 Then", and thought you meant "If $regexp_result = 1 Then", so that's what appears. Also commented out a function we don't have "_SetStatus("Abgebrochen.")" and just made that return 0. Again, this just simplifies testing only the regexp for now.

:D

Edit: Oops, $new_cal_name was incorrectly set to Local.

Edit: Ahh, substituted an apostrophe for the funky HTML "'".

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Thanks,

but maybe someone can just post the example how to check whether a string only contains a-zA-Z-_ or blanks.

I tried this. :"> Didn't work until yet.

Global $a = "HelloMegas"
$return = StringRegExp($a, "([A-Za-z0-9\_\- ])", 3)
If @extended = 0 Then
    MsgBox(0, "Info", "Found any bad char")
EndIf

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thank you very much, ...

Your brought me to the right way for easy testing!

Wikipedia brought me to the right pattern and my mind remembered that you have to put the space not at the begininning nor the end of an [...l] group. Thanks to all!

Here my solution:

Global $new_cal_name
While 1
     $Returned = _TestInput()
     If MsgBox(64 + 1, "RegExp Test", "$Returned = " & $Returned & ", $new_cal_name = " & $new_cal_name) <> 1 Then Exit
Wend

; -----------------------------
;   _TestInput($sInpt)
;   Return 1 for valid input string, 0 for invalid
; -----------------------------
Func _TestInput()
     While 1
         $new_cal_name = InputBox("Kalendername", "Bitte geben Sie den Namen des neuen Kalenders an:", "NeuerKalender1")
          If @error = 1 Then ; Abbrechen geklickt
               ; _SetStatus("Abgebrochen.")
               Exit               
          Else ; String checken!!!!!!!!
               $regexp_result = StringRegExp($new_cal_name, "^[A-Za-z0-9_ -]+$", 0)
               If $regexp_result = 1 Then
                    ; richtig
                    Return 1
                    ExitLoop
               Else
                    Return 0
;~      ContinueLoop
               EndIf
          EndIf
     WEnd
EndFunc ; ===>_TestInput

@Help file / neogia: Would you please mention in the tutorial that ^outside of a group codes the beginning of the test string and $ codes its end? This is VERY helpful when examining whole strings for correctness. I got this information on http://de.wikipedia.org/wiki/Regul%C3%A4re_Ausdr%C3%BCcke. Thanks!

peethebee

Edited by peethebee

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvGerman Forums: http://www.autoit.deGerman Help File: http://autoit.de/hilfe vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

Share this post


Link to post
Share on other sites

A bit late but I did this before you replied with your answer:

#Include <Array.au3>
Global $s_temp = "test_   3424#$%"
$a_return = StringRegExp($s_temp, "[^A-Za-z0-9_ -]", 3)
If @extended = 1 Then
    MsgBox(0, "Info", "A bad char was found!")
    _ArrayDisplay($a_return, "Bad Characters")
Else
    MsgBox(0, "Info", "No bad char was found!")
EndIf

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

That's logic too...

I had just aknot in my head ;-)

Thanks. Perhaps it will help others who use the forums' search...

peethebee


vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvGerman Forums: http://www.autoit.deGerman Help File: http://autoit.de/hilfe vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

Share this post


Link to post
Share on other sites

Actually , I wonder why that is not returning the bad characters to the array? Why is $a_Return empty?


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

Actually , I wonder why that is not returning the bad characters to the array? Why is $a_Return empty?

Because there's no captures specified, just a character set.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Because there's no captures specified, just a character set.

Wow... silly mistake. :">

EDIT: This works much better:

#Include <Array.au3>
Global $s_temp = "test_   3424#$%"
$a_return = StringRegExp($s_temp, "([^A-Za-z0-9_ -])", 3)
If @extended = 1 Then
    MsgBox(0, "Info", "A bad char was found!")
    _ArrayDisplay($a_return, "Bad Characters")
Else
    MsgBox(0, "Info", "No bad char was found!")
EndIf

Now, why isnt the money symbol in the array of bad characters?

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

Hi,

I think it would be great if someone could expand the helpfile for SRE with some good easy examples.

Many users have to go along with trial&error for no reason.

Just a thought.

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Hi,

I think it would be great if someone could expand the helpfile for SRE with some good easy examples.

Many users have to go along with trial&error for no reason.

Just a thought.

So long,

Mega

I read a lot of tutorials on RegExp's for other langauges and see what is applicable for AutoIt. It would be nice if Neogia would release Part II to his tutorial with some advanced regular expressions.

I still would like to know why the $ symbol isnt returned to the array.


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