Jump to content
Sign in to follow this  
Renshai

Search/Replace using regular expression?

Recommended Posts

Renshai

Hello -

I'm sorry if posting this is a sin and I'm asking a question that has been answered before. I have legitimately spent two hours googling and searching these forums to answer what I assume is a fairly simple problem. I've used the regular expression replace function in some other applications, for making comprehensive changes to code. In the programs I've used and am familiar with, I'd use something along these lines:

Find what: SEND("(w+)")

Replace with: The previous line would have sent 1!

This would have found a line that said: SEND("{ESCAPE}") and replaced it with "The previous line would have sent {ESCAPE}!"

I've puzzled out how to MATCH the line I want to replace, for this application it would be

Find What: MOUSECLICK("Left", w+, w+, w+) [d+ works fine too]

But I cannot for the life of me figure out how to call that matched text in the replace function, and I cannot find a solution online. Granted it is 5am and I've been staring at this long enough to have manually changed every instance 10 times over, but I'm stubborn and want to know for future use.

Thanks, sorry if I just missed the solution answered elsewhere, its 5am like I said.

Share this post


Link to post
Share on other sites
PhoenixXL

Welcome to the FORUM Renshai :)

Can you post the code you are using at the moment and the expected result that the code fail to give ?

To post Autoit code press the in the formatting options of the editor and paste the code in the window that appears.

Regards :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
Renshai

I'm not trying to execute a code. I am using the Autoit editor's built in replace function, that allows for regular expressions, found in the Search -> Replace menu option.

Share this post


Link to post
Share on other sites
Renshai

I solved my problem by using a code editor that works as expected. =P

If anyone knows the syntax to use the built in function, feel free to post a response.

Share this post


Link to post
Share on other sites
Melba23

Renshai,

Could I just point out that it is not the "AutoIt editor", but the "SciTE editor" with some tweaks to make it better for AutoIt coding. ;)

Anyway, that took some finding! You need to use "(" and ")" to delimit the capturing group - so using this as the Find:

SEND("\(.*\)")
and this as the Replace:

The previous line would have sent \1
carries out the replacement as you required. :)

It is the find.replace.regexp.posix property that sets the capture boundary characters:

 

find.replace.regexp.posix

Change behaviour of Regular expression search. If set to 0 (the default), characters '(' and ')' must be escaped by '' to behave as regexp meta characters. If set to 1, these characters are meta characters itself.

I hope you slept well - coding at 5AM is seldom a good idea. :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Renshai

I appreciate the response! And I wasn't aware that the editor wasn't inherent to the program, my mistake. I was a little frustrated after banging my tired head against the keyboard for so long, so I'm sorry if the tone of my message conveyed that. This answer explains why I could use w+ to catch a fragment of a line but not use it, and why (w+) would not catch anything at all. It was looking for the "(" as a character in the line of text, which is something I probably would have thought to check if it wasnt 5am =D

On a side note, where do I modify this setting? I ran a search of file contents in the autoit program folder and turned up nothing.

Thank you.

Share this post


Link to post
Share on other sites
Melba23

Renshai,

No problem - as I mentioned we are rarely at our best at 5AM. :D

You find the SciTE options like the find.replace.regexp.posix one I mentioned above in the Global Options file (SciTE menu: <Options - Open Global Options File>). If you look in there you will see that this option has been commented out, meaning that the default is used. :)

But I would not advise changing that file as it is overwritten when you update. Better to add the line to the User Options file (SciTE menu: <Options - Open User Options File>) as this is retained during updates. ;)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

×