Move matching text from end of line, to start of line Topic is solved
Move matching text from end of line, to start of line
Hi!
It is possible to move specific text form line end to start ?
At following example, i want to move "sample text" to the start of line.
"this is nice, sample text"
I want to convert it to
"sample text , this is nice"
(My actual text is copied from webpage, to clipboard)
It is possible to move specific text form line end to start ?
At following example, i want to move "sample text" to the start of line.
"this is nice, sample text"
I want to convert it to
"sample text , this is nice"
(My actual text is copied from webpage, to clipboard)
Re: Move matching text from end of line, to start of line
I believe that your current description is inadequate, because it does not explain, comprehensively and in detail, exactly how to handle punctuation. A script could be written to handle your individual specific example as posted, but the question would then quickly arise, "Yes, but what if....?" Thus, my suggestion is for you write a list of every rule that would be applied, to get from input to output. This task in itself requires no knowledge of coding. The rules can then be transformed into code.
Re: Move matching text from end of line, to start of line
Thank you mikeyww for the reply!
I want to use the result for generating (for e-shop product), seo friendly url field.
I don΄t care for punctuation, the whole line will be converted again, using build in php function
I only need a space between moved text and line start.
The texts I want to move from end to front are about 10, "canvas print", "wall stickers", "Room divider"
At following examples i need only the "Script result"
Detailed example:
Product tittle:
Celebration of July in Paris, van Gogh Vincent, canvas print ; I want to move the the text "canvas print " from end, to front
Script result:
canvas print Celebration of July in Paris, van Gogh Vincent,
Build in php function result
canvas-print-celebration-of-july-in-paris-van-gogh-vincent
Another example
Product tittle:
Blooming cherry, pink, white flowers wall stickers ; I want to move the the text " wall stickers" from end, to front
Script result:
wall stickers Blooming cherry, pink, white flowers
Build in php function result
wall-stickers-blooming-cherry-pink-white-flowers
I will paste the Script result to my eshop software, Friedly url generator, and the build in php function will convert it
It removes commas, replaces spaces with minus etc
I hope description is better now!
Actual product links
https://www.stickit.gr/en/canvas-prints/fine-art-prints/global-artists/canvas-print-celebration-of-july-in-paris-van-gogh-vincent
https://www.stickit.gr/en/wall-stickers/nature/wall-stickers-blooming-cherry-pink-white-flowers
I want to use the result for generating (for e-shop product), seo friendly url field.
I don΄t care for punctuation, the whole line will be converted again, using build in php function
I only need a space between moved text and line start.
The texts I want to move from end to front are about 10, "canvas print", "wall stickers", "Room divider"
At following examples i need only the "Script result"
Detailed example:
Product tittle:
Celebration of July in Paris, van Gogh Vincent, canvas print ; I want to move the the text "canvas print " from end, to front
Script result:
canvas print Celebration of July in Paris, van Gogh Vincent,
Build in php function result
canvas-print-celebration-of-july-in-paris-van-gogh-vincent
Another example
Product tittle:
Blooming cherry, pink, white flowers wall stickers ; I want to move the the text " wall stickers" from end, to front
Script result:
wall stickers Blooming cherry, pink, white flowers
Build in php function result
wall-stickers-blooming-cherry-pink-white-flowers
I will paste the Script result to my eshop software, Friedly url generator, and the build in php function will convert it
It removes commas, replaces spaces with minus etc
I hope description is better now!
Actual product links
https://www.stickit.gr/en/canvas-prints/fine-art-prints/global-artists/canvas-print-celebration-of-july-in-paris-van-gogh-vincent
https://www.stickit.gr/en/wall-stickers/nature/wall-stickers-blooming-cherry-pink-white-flowers
Re: Move matching text from end of line, to start of line
From where to receive the info on what text/words should be swapped?to move specific text
The below script will take a string that has been copied to the clipboard (press Alt+c) and converts it as requested.
Output is copied to the clipboard.
Code: Select all
#SingleInstance, Force
;str := "Celebration of July in Paris, van Gogh Vincent, canvas print"
;str := "Blooming cherry, pink, white flowers wall stickers"
!c:: ; press Alt+c
Send ^c ; copy whatever text you've selected to the clipboard
ClipWait ; wait till clipboard contains content
if (clipboard="")
Return
StringLower, clipboard, str ; convert text to lower case
arr := StrSplit(StrReplace(str,",",""),A_Space) ; remove commas, split at whatever space character
url := arr[arr.Count()-1] "-" arr[arr.Count()] ; set the last two words to the front
Loop % arr.Count()-2 ; loop for array items (except the last two)
url .= "-" arr[A_Index] ; add the remaining words
Msgbox % clipboard := url ; copy converted str to clipboard
Return
Re: Move matching text from end of line, to start of line
Code: Select all
#NoEnv
Terms := "canvas print|wall stickers|room divider" ; search terms divided by pipe |
Titles := ["Celebration of July in Paris, van Gogh Vincent, canvas print"
, "Blooming cherry, pink, white flowers wall stickers"
, "Any other arbitrary text."]
For Each, Title In Titles {
Result := RegExReplace(Title, "i`a)(.*)(" . Terms . ")$", "$2 $1")
MsgBox, %Title%`n->`n%Result%
}
ExitApp
Re: Move matching text from end of line, to start of line
More of the same....
Code: Select all
str = Celebration of July in Paris, van Gogh Vincent, canvas print
move = canvas print
MsgBox, 64, Output, % strMove(str, move)
strMove(str, move) {
Return RegExReplace(str, "(.+) (" move ")$", "$2 $1")
}
Re: Move matching text from end of line, to start of line
Thank you @BoBoBoBo wrote: ↑03 Mar 2022, 04:01From where to receive the info on what text/words should be swapped?to move specific text
The below script will take a string that has been copied to the clipboard (press Alt+c) and converts it as requested.
Output is copied to the clipboard.
Code: Select all
#SingleInstance, Force ;str := "Celebration of July in Paris, van Gogh Vincent, canvas print" ;str := "Blooming cherry, pink, white flowers wall stickers" !c:: ; press Alt+c Send ^c ; copy whatever text you've selected to the clipboard ClipWait ; wait till clipboard contains content if (clipboard="") Return StringLower, clipboard, str ; convert text to lower case arr := StrSplit(StrReplace(str,",",""),A_Space) ; remove commas, split at whatever space character url := arr[arr.Count()-1] "-" arr[arr.Count()] ; set the last two words to the front Loop % arr.Count()-2 ; loop for array items (except the last two) url .= "-" arr[A_Index] ; add the remaining words Msgbox % clipboard := url ; copy converted str to clipboard Return
Yes my input is text from clipboard.
Your code works fine!
I will accept the next answer from @just me only because i can use the multiple search terms divided by pipe | , but i will use your part of code for converting text to lower case and remove commas
Re: Move matching text from end of line, to start of line Topic is solved
Thank you @just mejust me wrote: ↑03 Mar 2022, 06:23?Code: Select all
#NoEnv Terms := "canvas print|wall stickers|room divider" ; search terms divided by pipe | Titles := ["Celebration of July in Paris, van Gogh Vincent, canvas print" , "Blooming cherry, pink, white flowers wall stickers" , "Any other arbitrary text."] For Each, Title In Titles { Result := RegExReplace(Title, "i`a)(.*)(" . Terms . ")$", "$2 $1") MsgBox, %Title%`n->`n%Result% } ExitApp
Your script fits exactly my needs, especially because I can use the multiple search terms divided by pipe | !
Last edited by siomosp on 03 Mar 2022, 16:32, edited 2 times in total.
Re: Move matching text from end of line, to start of line
Thank you @mikeywwmikeyww wrote: ↑03 Mar 2022, 07:28More of the same....
Code: Select all
str = Celebration of July in Paris, van Gogh Vincent, canvas print move = canvas print MsgBox, 64, Output, % strMove(str, move) strMove(str, move) { Return RegExReplace(str, "(.+) (" move ")$", "$2 $1") }
One more time your script is excellent , but i will use @just me mainly because I can use the multiple search terms divided by pipe |
Re: Move matching text from end of line, to start of line
A good choice. I'd always go with just me's code as well
Btw, my code isn't using a static 'matchlist' as it uses the more dynamic filter criteria taking the last two words of a string by default.
So no need to "pre-configure" a list, the main reason why I asked, "From where to receive the info on what text/words should be swapped?".
Something, AFAICS mikeyww has pointed out before already. It's all about specs
Happy scripting
Btw, my code isn't using a static 'matchlist' as it uses the more dynamic filter criteria taking the last two words of a string by default.
So no need to "pre-configure" a list, the main reason why I asked, "From where to receive the info on what text/words should be swapped?".
Something, AFAICS mikeyww has pointed out before already. It's all about specs
Happy scripting