Jump to content

StringRegExp


Recommended Posts

hi

I dont quite understand how StringRegExp works so im asking if someone can explain a little

in the help file i find this (.*?) really confusing, because i cant find what this means nor where is it taken from I do understand that $array[1] is equal to a in the string: see code where i took it:

$array = StringRegExp('<test>a</test> <test>b</test> <test>c</Test>', '<(?i)test>(.*?)</(?i)test>', 2)oÝ÷ Ù¶¬Æ¥"0j{m¡ø§vêiz·±ç!j»vÊZqæÞ·êiz¶¦¦Z0z·±æ2¢ëz)¥ÛezZ,¶«y«­¢+ØÀÌØíÉÉäôÌäí ½Ñ%½Ñ9½Ñ½Ñ=½ÑÌäì((ÀÌØí½¼ôMÑÉ¥¹IáÁIÁ± ÀÌØíÉÉä°ÅÕ½ÐímléÕÁÁÈéutÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤()5Í  ½à À°ÅÕ½ÐìÅÕ½Ðì°ÀÌØí½¼¤)á¥Ð
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

Try

$array = 'BotaIotaNotaGotaOota'

$boo =  StringRegExpReplace($array, "[[:upper:]]", "\0 ")

MsgBox(0, "",$boo )
Exit
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

Try

$array = 'BotaIotaNotaGotaOota'

$boo =  StringRegExpReplace($array, "[[:upper:]]", "\0 ")

MsgBox(0, "",$boo )
Exit
Reading what he wrote, it almost seems what he wants is what you gave him... but I have a sneaky suspicion it's more:
$array = 'BotaIotaNotaGotaOota'

$boo =  StringRegExpReplace($array, "[[:upper:]]", " \0")

MsgBox(0, "",$boo )

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

Reading what he wrote, it almost seems what he wants is what you gave him... but I have a sneaky suspicion it's more:

$array = 'BotaIotaNotaGotaOota'

$boo =  StringRegExpReplace($array, "[[:upper:]]", " \0")

MsgBox(0, "",$boo )
Yes I think you're right SmoOke_N, I didn't think very hard about what I was achieving there :) :)
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

yup this is it thank you all.

Yet can you explain what exactly this means? Since i cant find this in the help file.

$0 = ?


\ = match the actual character, hire it is uppercase letter?
0 = indicates all uppercase chars hire?
\0 = replace all uppercase chars
Edited by goldenix
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

yup this is it thank you all.

Yet can you explain what exactly this means? Since i cant find this in the help file.

$0 = ?


\ = match the actual character, hire it is uppercase letter?
0 = indicates all uppercase chars hire?
\0 = replace all uppercase chars
\0 or $0 in the replace string means use the first character in the match that was found.

\1 \2 \3 for the second, third forth etc.

$3-$7 means (I think) use characters 4 to 8 from the match.

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

\0 or $0 in the replace string means use the first character in the match that was found.

\1 \2 \3 for the second, third forth etc.

$3-$7 means (I think) use characters 4 to 8 from the match.

according to you this should replace only the first uppercase letter but its does not:

$array = '_BotaIotaNotaGotaOota'
$boo =  StringRegExpReplace($array, "[[:upper:]]", " \1") ; or \0
MsgBox(0, "",$boo )
ExitoÝ÷ ÚëzZqæ¥êiz·±ç!j»Åêm~*ì¶Þjëh×6$array = '_BotaIotaNotaGotaOota'
$boo =  StringRegExpReplace($array, "[[:upper:]]", " $1-$0") ; or \0
MsgBox(0, "",$boo )
Exit
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

I'm far from experienced in Regular Expressions, but what martin means with $3-$7 is probably 3 To 7.

I did a little testing, and it seems $0 Or \0 doesn't replace the character itself, only using 1, and up does that.

Just to make it clear, try this:

$array = '_BotaIotaNotaGotaOota'
$boo =  StringRegExpReplace($array, "[[:upper:]]", "<$0>")
MsgBox(0, "",$boo )

As you see $0 or \0 is the marker where it found the expression..

Link to comment
Share on other sites

aha. k thanx for the answers.

Basically i needed to rename couple thousands subfolders, so this is the script I used, if someone is interested:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.11.1 (beta)

 Script Function:
 
 will add space in front of uppercase chars in the folder [will read folder path from clipboard]
 
 
 Samples:
    $array = '_BotaIotaNotaGotaOota'
    $boo =  StringRegExpReplace($array, "[[:upper:]]", "<$0>") ; _<B>ota<I>ota<N>ota<G>ota<O>ota As you see $0 or \0 is the marker where it found the expression..
    MsgBox(0, "",$boo )
    Exit

    $array = '_BotaIotaNotaGotaOota'
    $boo =  StringRegExpReplace($array, "[[:upper:]]", " 0") ; or \0
    $boo =  StringReplace($boo, " ", "",1); we dont need space in front of the first letter
    MsgBox(0, "",$boo )
    Exit
    
#ce ----------------------------------------------------------------------------

MsgBox(0,"",clipget()); get folder path from clipboard

Dim $FolderName = clipget()
Dim $FileCount = 0
Global $folder

ScanFolder($FolderName)

MsgBox(0,"Done","Folder renaming Complete")

Func ScanFolder($SourceFolder)
    Local $Search
    Local $File
    Local $FileAttributes
    Local $FullFilePath
    
    $Search = FileFindFirstFile($SourceFolder & "\*.*")  

    While 1
        If $Search = -1 Then
            ExitLoop
        EndIf
        
        $File = FileFindNextFile($Search)
        If @error Then ExitLoop
        
        $FullFilePath = $SourceFolder & "\" & $File
        $FileAttributes = FileGetAttrib($FullFilePath)
        
        $folder = $SourceFolder


        
        If StringInStr($FileAttributes,"D") Then ; if its a folder then
            ScanFolder($FullFilePath)
            
            $boo =  StringRegExpReplace($File, "[[:upper:]]", " $0") ; or \0
            $boo =  StringReplace($boo, " ", "",1); we dont need space in front of the first letter         
                
;~              $a = StringSplit($SourceFolder,"\",0) ; $a[$a[0]] = folder name
;~              DirMove($FullFilePath, $SourceFolder & "\" & $a[$a[0]] & ' - ' & $boo) ; this will add folder name in front of all subfolders  [..\pics\family pics\me & jane folder] = [..\pics\family pics\family pics - me & jane folder]

                DirMove($FullFilePath, $SourceFolder & "\" & $boo) ; this will simply add spaces in front uppercase chars in all subfolders


        EndIf

    WEnd

    FileClose($Search)
EndFunc
Edited by goldenix
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

Hmm, I don't really see what this accomplishes, as you can't have a leading space in a folder name in windows...

Or am I getting some bad vibes by the wine I'm drinking?(note: I didn't miss-spell wine this time ^___ ^) heh

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