Jump to content

StringRegExpReplace Help?


gseller
 Share

Recommended Posts

Help? Can someone help me get this to work?

$r = StringRegExpReplace("Pass1234", "[a-zA-Z]", "\0{ENTER}")
;$r = StringRegExpReplace("Pass1234", "[0-9]", "{NUMPAD\0}")
MsgBox(0, "ACD login Info entered", $r)

I want to make a string like the above aplha/numeric use keycode.

Explanation: Let say I have the password "Pass1234", I want to turn StringRegExpReplace this into:P{ENTER}a{ENTER}s{ENTER}s{ENTER}1{NUMPAD}2{NUMPAD}3{NUMPAD}4{NUMPAD}

EDIT: Changed [a-z] to "[a-zA-Z]", this gives me P{ENTER}a{ENTER}s{ENTER}s{ENTER}1 and the second StringRegExpReplace will make the 1{NUMPAD}2{NUMPAD}3{NUMPAD}4{NUMPAD} but how can I make on regex that doea it all?

Edited by gesller
Link to comment
Share on other sites

Hi gesller,

You can't do it via one StringRegExpReplace, because it's not supports multi-replacement (too bad). Try this UDF:

Dim $sString        = "Pass1234"
Dim $aPattern[2]    = ["[a-zA-Z]", "[0-9]"]
Dim $aReplace[2]    = ["\0{ENTER}", "{NUMPAD\0}"]

$sString = _StringRegExpMultiReplace($sString, $aPattern, $aReplace)

MsgBox(0, "ACD login Info entered", $sString)

Func _StringRegExpMultiReplace($sString, $aPattern, $aReplace)
    If Not IsArray($aPattern) Or Not IsArray($aReplace) Then Return SetError(1, 0, $sString)
    
    Local $iExtended = 0
    ReDim $aReplace[UBound($aPattern)]
    
    For $i = 0 To UBound($aPattern)-1
        $sString = StringRegExpReplace($sString, $aPattern[$i], $aReplace[$i])
        $iExtended += @extended
    Next
    
    Return SetError(0, $iExtended, $sString)
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Hi gesller,

You can't do it via one StringRegExpReplace, because it's not supports multi-replacement (too bad). Try this UDF:

Dim $sString       = "Pass1234"
Dim $aPattern[2]    = ["[a-zA-Z]", "[0-9]"]
Dim $aReplace[2]    = ["\0{ENTER}", "{NUMPAD\0}"]

$sString = _StringRegExpMultiReplace($sString, $aPattern, $aReplace)

MsgBox(0, "ACD login Info entered", $sString)

Func _StringRegExpMultiReplace($sString, $aPattern, $aReplace)
    If Not IsArray($aPattern) Or Not IsArray($aReplace) Then Return SetError(1, 0, $sString)
    
    Local $iExtended = 0
    ReDim $aReplace[UBound($aPattern)]
    
    For $i = 0 To UBound($aPattern)-1
        $sString = StringRegExpReplace($sString, $aPattern[$i], $aReplace[$i])
        $iExtended += @extended
    Next
    
    Return SetError(0, $iExtended, $sString)
EndFunc

WOW! That is Phenominal! I am so glad I asked. Thank you so much!

Link to comment
Share on other sites

Help? Can someone help me get this to work?

$r = StringRegExpReplace("Pass1234", "[a-zA-Z]", "\0{ENTER}")
;$r = StringRegExpReplace("Pass1234", "[0-9]", "{NUMPAD\0}")
MsgBox(0, "ACD login Info entered", $r)

I want to make a string like the above aplha/numeric use keycode.

Explanation: Let say I have the password "Pass1234", I want to turn StringRegExpReplace this into:P{ENTER}a{ENTER}s{ENTER}s{ENTER}1{NUMPAD}2{NUMPAD}3{NUMPAD}4{NUMPAD}

EDIT: Changed [a-z] to "[a-zA-Z]", this gives me P{ENTER}a{ENTER}s{ENTER}s{ENTER}1 and the second StringRegExpReplace will make the 1{NUMPAD}2{NUMPAD}3{NUMPAD}4{NUMPAD} but how can I make on regex that doea it all?

You could do this as well.

$string = "Pas1234"
$r = StringRegExpReplace(StringRegExpReplace($string, "([a-zA-Z])", "\0{ENTER}"),"[0-9]","{NUMPAD\0}")

MsgBox(0, "ACD login Info entered", $r)
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

You could do this as well.

$string = "Pas1234"
$r = StringRegExpReplace(StringRegExpReplace($string, "([a-zA-Z])", "\0{ENTER}"),"[0-9]","{NUMPAD\0}")

MsgBox(0, "ACD login Info entered", $r)

That works very well also.. Thanks so much!

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