RegEx: remove/keep words of a specific case

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 6708
Joined: 19 Dec 2016, 01:58
Location: UK

RegEx: remove/keep words of a specific case

24 Aug 2019, 13:55

I've written some code to remove/keep words of a specific case from a list.
I'm posting in case anybody has any other ideas.

Code: Select all

q:: ;remove/keep words of a specific case
vText := " ;continuation section
(
UPPER
miXeD
MiXeD
miXeD
miXed
Title
lower
=
abc
Abc
ABC
=
ABc
AbC
aBC
aBc
abC
=
DEF
Def
def
)"

;remove lower:
MsgBox, % "remove L`r`n[" RegExReplace(vText, "m`n)^[a-z]+(\R|$)") "]"

;remove upper:
MsgBox, % "remove U`r`n[" RegExReplace(vText, "m`n)^[A-Z]+(\R|$)") "]"

;remove title:
MsgBox, % "remove T`r`n[" RegExReplace(vText, "m`n)^[A-Z][a-z]+(\R|$)") "]"

;remove mixed:
;note: mixed: U followed by at least 1 U *and* 1 L, L followed by at least 1 U
MsgBox, % "remove X`r`n[" RegExReplace(vText, "m`n)^([A-Z](?=.*[A-Z])(?=.*[a-z])|[A-Z](?=.*[a-z])(?=.*[A-Z])|[a-z](?=.*[A-Z])).*(\R|$)") "]"

MsgBox

;keep lower: remove title/upper/mixed [no upper-case characters]
MsgBox, % "get L`r`n[" RegExReplace(vText, "m`n)^(?=.*[A-Z]).*(\R|$)") "]"

;keep upper: remove title/lower/mixed [no lower-case characters]
MsgBox, % "get U`r`n[" RegExReplace(vText, "m`n)^(?=.*[a-z]).*(\R|$)") "]"

;keep title: remove lower/upper/mixed [can't start with lower case, can't be 'starts with upper, later contains upper']
MsgBox, % "get T`r`n[" RegExReplace(vText, "m`n)^([a-z]|[A-Z](?=.*[A-Z])).*(\R|$)") "]"

;keep mixed: remove lower/upper/title [can't be all upper, can't be '2nd character onwards lower']
MsgBox, % "get X`r`n[" RegExReplace(vText, "m`n)^([A-Z]+|.[a-z]*)(\R|$)") "]"
return

;remove lines that contain string
;vText := RegExReplace(vText, "m)^.*\Q" vNeedle "\E.*(\R|$)")
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: chngrcn, Odlanir, pf_moore, VonVon, yjs778 and 56 guests