Jump to content

{} and StringRegExpReplace


Recommended Posts

Greetings,

is there a non-ClipGet alternative for StringRegExpReplace?

I need to swap word1 with expression {word2|word3|word4}

AutoIt Help says: "To separate back-references from actual (replaced) numbers, wrap it with half-round brackets, i.e: "${1}5"."

so, i get an output with errors because of the above mentioned built-in functionality

any ideas?

thanks

Link to comment
Share on other sites

  • Moderators

yton,

We need a bit more than that to offer any sensible advice. :)

Please give us at least one example of an original and a final string, together with what you have been using as code to run the RegEx . :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 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

 

Link to comment
Share on other sites

While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button1
                $title = GUICtrlRead($Input1, 1)
                $title = StringRegExpReplace($title, "word1", "{word2|word3|word4}")
                Run('Notepad.exe')
                Sleep(1000)
                Send($title)
        EndSelect
    WEnd
EndFunc

Link to comment
Share on other sites

Again, as @Melba23 requested, we need more info. What is your input string? What do you want the returned string to be? It's hard to understand what exactly you are trying to do without a better explanation. As it is right now, it appears that you have the pattern and replacement values switched. Perhaps you meant:

$title = StringRegExpReplace($title, "{word2|word3|word4}", "word1")
Link to comment
Share on other sites

  • Moderators

yton,

What are "word1" and "{word2|word3|word4}"? Are they literal strings? :idea:

Because if so the RegEx will only ever do anything if you have the literal string "word1" in $title.

Are you looking to replace the first word of $title with other words?

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

 

Link to comment
Share on other sites

well, i have a form with $Input1

say, i put there (in $Input1) the sentence: "Word1 bla bla bla bla bla"

the required output sentence is "{Word2|Word3|Word4} bla bla bla bla bla", where

1) Word1, Word2, Word3 and Word4 are simple words like (e.g.) Big, Huge, Massive, Great

2) first word or not - it is not important. Word1 can be anywhere in the sentense

The thing is that i cannot get exact element "{Word2|Word3|Word4}" using StringRegExpReplace as AutoIt Help says the following about this function: "To separate back-references from actual (replaced) numbers, wrap it with half-round brackets, i.e: "${1}5"."

so, i get an output with errors because of the above mentioned built-in functionality

so, i need to leave StringRegExpReplace for other function that will provide exactly {Word2|Word3|Word4} with half-round brackets

Edited by yton
Link to comment
Share on other sites

  • Moderators

yton,

Why did you think you needed "back-references"? :idea:

What you need is to escape the curly brackets so the RegEx recognises tham as part of the pattern: :)

$sString = "bla bla Word1 bla bla"

$sResult = StringRegExpReplace($sString, "(?i)(Word1)", "\{Word2|Word3|Word4\}")

MsgBox(0, "Result", $sResult)

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

 

Link to comment
Share on other sites

thank you all )

the solution is simple as @#$%^^&

While 1         
$msg = GUIGetMsg()         
Select             
Case $msg = $GUI_EVENT_CLOSE                 
ExitLoop             
Case $msg = $Button1                 
$title = GUICtrlRead($Input1, 1)                 
$title = StringRegExpReplace($title, "word1", "{word2|word3|word4}")                 
Run('Notepad.exe')                 
Sleep(1000)                 
Send($title, 1) ; this is it! 
EndSelect     
WEnd 
EndFunc
Edited by yton
Link to comment
Share on other sites

Again, as @Melba23 requested, we need more info. What is your input string? What do you want the returned string to be? It's hard to understand what exactly you are trying to do without a better explanation. As it is right now, it appears that you have the pattern and replacement values switched. Perhaps you meant:

$title = StringRegExpReplace($title, "{word2|word3|word4}", "word1")

I know, old habits die hard.

Just an FYI, that RegEx example you posted will fail miserably with PCRE because of the curly braces and a lack of word boundary matching.

I think what you wanted was "\b(word2|word3|word4)\b"

\b is for word boundary to make sure it's only complete words and without that you could run into a problem like word2 actually being the word "and" where it would match

"wand", "band", "and", "land" & etc

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Moderators

George,

When I grow up will I be able to understand SREs too? :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 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

 

Link to comment
Share on other sites

That question begs 2 more questions:

  • With all the available flavors of SRE, does anyone truly understand them all?
  • Are you ever going to grow up?

EDIT: I think I gave you a link for testing SRE's. Try using it. It was updated today too.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Moderators

George,

1. I hope not - who would want to live in that brain? :idea:

2. You must have guessed my motto: "Growing old is obligatory - growing up is entirely voluntary!" :)

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

 

Link to comment
Share on other sites

George,

1. I hope not - who would want to live in that brain? :idea:

2. You must have guessed my motto: "Growing old is obligatory - growing up is entirely voluntary!" :)

M23

Great motto and I subscribe to that 100%. Now go back and read my edit, which was done to make your life easier.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Moderators

George,

How do you think I tested the one I suggested? :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 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

 

Link to comment
Share on other sites

George,

How do you think I tested the one I suggested? :idea:

M23

Well I didn't test it but it must work then. Suggest the update though, there was a serious typo in the old one and I still don't know why it never threw an error.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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