Hello, seeking a regex to only copy sequential capitalized words in a sentence.
For example:
Good MORNING everyone. Have a good day.
So if I highlight the text above and copy, only MORNING is copied?
Thanks a bunch.
Regex to only copy sequential capitalized words Topic is solved
Re: Regex to only copy sequential capitalized words Topic is solved
Hallo,
try:
try:
Code: Select all
ClipBoard = Good MORNING everyone. Have a good day.
RegExMatch(ClipBoard, "([A-Z]{2,})", M)
MsgBox,% M1
Re: Regex to only copy sequential capitalized words
morning was just an example, i meant cap words in general
Re: Regex to only copy sequential capitalized words
What makes you think it works only with the word "morning"? If it's because of the first line, that's just for providing the demonstration. You said you wanted the RegEx itself. Do you need the code to implement the RegEx when the clipboard gets new text copied to it?
Re: Regex to only copy sequential capitalized words
Are you swedish?
Then:
Then:
Code: Select all
ClipBoard = Ha ett trevligt ÅR
RegExMatch(ClipBoard, "(\p{Lu}{2,})", M)
MsgBox,% M1
Re: Regex to only copy sequential capitalized words
I see sorry I added it wrong to my ahk but got it to work now as you had it is correct
Re: Regex to only copy sequential capitalized words
Is there any modification I can make to that to only copy words that are 3 to 4 letters only?
Re: Regex to only copy sequential capitalized words
Yes, try
Code: Select all
ClipBoard = HA ETT TREVLIGT ÅR
RegExMatch(ClipBoard, "(\p{Lu}{3,4})", M)
MsgBox,% M ; On this pattern, M and M1 give the same output
/* Output:
ETT
*/
Re: Regex to only copy sequential capitalized words
Thanks for the quick reply, i tried the above, but if there is a word with more thatn 3 letters first, it copies that but the first four letters of that word. I want it to skip those all together. So with the scriptsofista wrote: ↑16 Jun 2021, 16:49Yes, try
Edited: Posted a better exampleCode: Select all
ClipBoard = HA ETT TREVLIGT ÅR RegExMatch(ClipBoard, "(\p{Lu}{3,4})", M) MsgBox,% M ; On this pattern, M and M1 give the same output /* Output: ETT */
ALERT BUY the outcome is ALER, whereas I just want BUY to be copied.
Re: Regex to only copy sequential capitalized words
You're welcome. Try this other regex, will match the first word with three or four letters:Shanghei wrote: ↑16 Jun 2021, 17:05Thanks for the quick reply, i tried the above, but if there is a word with more thatn 3 letters first, it copies that but the first four letters of that word. I want it to skip those all together. So with the script
ALERT BUY the outcome is ALER, whereas I just want BUY to be copied.
Code: Select all
ClipBoard = ALERT BUY the outcome is ALER
RegExMatch(ClipBoard, "\b(\p{Lu}{3,4})\b", M)
MsgBox, % M
/* Output:
BUY
*/
Re: Regex to only copy sequential capitalized words
that did it thankssofista wrote: ↑16 Jun 2021, 18:03You're welcome. Try this other regex, will match the first word with three or four letters:Shanghei wrote: ↑16 Jun 2021, 17:05Thanks for the quick reply, i tried the above, but if there is a word with more thatn 3 letters first, it copies that but the first four letters of that word. I want it to skip those all together. So with the script
ALERT BUY the outcome is ALER, whereas I just want BUY to be copied.
Code: Select all
ClipBoard = ALERT BUY the outcome is ALER RegExMatch(ClipBoard, "\b(\p{Lu}{3,4})\b", M) MsgBox, % M /* Output: BUY */
Re: Regex to only copy sequential capitalized words
Just a note: For international texts \b requires (*UCP).
Try:
Try:
Code: Select all
German = Umlaute machen häufig ÄRGER!
RegExMatch(German, "\b\p{Lu}{2,}\b", Ascii)
RegExMatch(German, "(*UCP)\b\p{Lu}{2,}\b", Unicode)
MsgBox,% "Ascii:`t" Ascii ; RGER
MsgBox,% "Unicode:`t" Unicode ; ÄRGER
Re: Regex to only copy sequential capitalized words
@Rohwedder Forgot to mention that. Thanks for the heads up
Who is online
Users browsing this forum: AlFlo, CuriousDad, Google [Bot] and 97 guests