Jump to content

Scite Regex Search&Replace


Recommended Posts

I have several statement like

GuiCtrlSetState($SomeControl,$GUI_HIDE)oÝ÷ Û^­ç(èqÍ4ÓK)j{-ÊWoÝ÷ Ùú+{¦¦W©àx-+ºÚ"µÍØÙHBÚ[Ù]]H
Ú[Ù]]J    ][ÝÉ][ÝÊK   ][ÝÉ][ÝË    ÌÍÜÕ]JBÕRPÝÙ]]J  ÌÍÓX[Ì×K   ÌÍÜÕ]JBÊÚÝÈÛÛÛÈ
ÕRPÝÙ]Ý]J   ÌÍÔXÖÌK    ÌÍÑÕRWÔÒÕÊBÕRPÝÙ]Ý]J    ÌÍÔXÖÌ×K  ÌÍÑÕRWÔÒÕÊBÕRPÝÙ]Ý]J    ÌÍÓX[ÌK ÌÍÑÕRWÔÒÕÊBÕRPÝÙ]Ý]J    ÌÍÓX[Ì×K   ÌÍÑÕRWÔÒÕÊBÕRPÝÙ]Ý]J    ÌÍÑÜXÖÌWK ÌÍÑÕRWÔÒÕÊBÐÛÛ[[Û]ÛÊ  ÌÍÚS[Ù
BÊYHÛÛÛÈ
ÕRPÝÙ]Ý]J   ÌÍÔXÖÌWK   ÌÍÑÕRWÒQJBÝZPÝÙ]Ý]J    ÌÍÓX[ÌK ÌÍÑÕRWÒQJBÝZPÝÙ]Ý]J    ÌÍÓX[ÍK ÌÍÑÕRWÒQJBoÝ÷ ÚÚºÚ"µÍØÙHBÚ[Ù]]H
Ú[Ù]]J    ][ÝÉ][ÝÊK   ][ÝÉ][ÝË    ÌÍÜÕ]JBÕRPÝÙ]]J  ÌÍÓX[Ì×K   ÌÍÜÕ]JBÊÚÝÈÛÛÛÈ
ÐÝÚÝÊ  ÌÍÔXÖÌJBÐÝÚÝÊ ÌÍÔXÖÌ×JBÐÝÚÝÊ   ÌÍÓX[ÌJBÐÝÚÝÊ  ÌÍÓX[Ì×JBÐÝÚÝÊ    ÌÍÑÜXÖÌWJBÐÛÛ[[Û]ÛÊ ÌÍÚS[Ù
BÊYHÛÛÛÈ
ÐÝYJ  ÌÍÔXÖÌWJBÐÝYJ    ÌÍÓX[ÌJBÐÝYJ  ÌÍÓX[ÍJB

Basically, the regular expression needs to find "GuiCtrlSetState(" and ",$GUI_HIDE)" and replace it with "_CtrlHide(" and ")" leaving the $SomeControl alone.

Can the regex feature of search and replace in scite accomplish this?? An example would be greatly appreciated.

In this is not possible within scite, can a lua scipt accomplish the task?

elTorro

Link to comment
Share on other sites

I'm feeling lazy... so no thinking about RegExp and IO.

Copy your code to the clipboard, then run the following script. Output will be in clipboard.

Dim $text = StringSplit( ClipGet(), @LF)
Dim $line, $new
Dim $output = ""

For $i = 1 to $text[0]
    $line = $text[$i]
    $new = $line
    If StringInStr($line, "GuiCtrlSetState") And StringInStr($line, "$GUI_SHOW") Then
        $new = StringReplace($new, "GuiCtrlSetState", "_CtrlShow")
        $new = StringReplace($new, ",$GUI_SHOW)", ")")
    ElseIf StringInStr($line, "GuiCtrlSetState") And StringInStr($line, "$GUI_HIDE") Then
        $new = StringReplace($new, "GuiCtrlSetState", "_CtrlHide")
        $new = StringReplace($new, ",$GUI_HIDE)", ")")
    EndIf
    
    $output = $output & $new & @LF
Next

ClipPut($output)
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

I'm feeling lazy... so no thinking about RegExp and IO.

Copy your code to the clipboard, then run the following script. Output will be in clipboard.

Dim $text = StringSplit( ClipGet(), @LF)
Dim $line, $new
Dim $output = ""

For $i = 1 to $text[0]
    $line = $text[$i]
    $new = $line
    If StringInStr($line, "GuiCtrlSetState") And StringInStr($line, "$GUI_SHOW") Then
        $new = StringReplace($new, "GuiCtrlSetState", "_CtrlShow")
        $new = StringReplace($new, ",$GUI_SHOW)", ")")
    ElseIf StringInStr($line, "GuiCtrlSetState") And StringInStr($line, "$GUI_HIDE") Then
        $new = StringReplace($new, "GuiCtrlSetState", "_CtrlHide")
        $new = StringReplace($new, ",$GUI_HIDE)", ")")
    EndIf
    
    $output = $output & $new & @LF
Next

ClipPut($output)
Thanks CyberSlug! ;)

Worked slicker than Owl doo on a tree limb. :evil:

Hey wait a min,

I coulda done that ...... If I'd thought of it :D:D:P dur duh doh

Good ole string functions.

@Anyone:

I would still be good to know if and how it can be done in scite though.

Link to comment
Share on other sites

HI,

two replaces. CTRL+H

1. GUICtrlSetState --> _CtrlHide

2. ,$GUI_HIDE --> ""

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

Link to comment
Share on other sites

  • Developers

Try this in SciTE:

1. Open Replace window

2. Tick Regular expression

3. type in "Find what": GuiCtrlSetState(\([a-z0-9$_/[/]]+\),$GUI_HIDE)

4. type in "Replace with": _CtrlHide(\1)

5. click "Replace All"

:D

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You might need to look again at the example :D Some of the GUICtrlSetState's are $GUI_SHOW

Oh sorry, missed that. But it should be done with 4 replaces. Which would be faster in this case, than thinking about the reg definition. (for me :"> )

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

Link to comment
Share on other sites

Oh sorry, missed that. But it should be done with 4 replaces. Which would be faster in this case, than thinking about the reg definition. (for me : )

So long,

Mega

I don't see how 4 replaces would work as in when you change GuiCtrlSetState.....

I fairly certain that regex in SciTE 's search and replace will not do the job either.

I don't make changes in scripts like this often, but sometimes it is handy. An external script may be better suited for such a task.

elTorro

Link to comment
Share on other sites

JdeB has the right idea, but I had to modify the regexp to get it to work:

First replacement:

GuiCtrlSetState(\([a-z0-9$_].*\),$GUI_HIDE)

_CtrlHide(\1)

Second replacement:

GuiCtrlSetState(\([a-z0-9$_].*\),$GUI_SHOW)

_CtrlShow(\1)

*This Should work*

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
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...