Regex capitalization glitch. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
kunkel321
Posts: 1049
Joined: 30 Nov 2015, 21:19

Regex capitalization glitch.

Post by kunkel321 » 23 Oct 2021, 16:00

Interesting thing here. With the code here, the bottom-most regexReplace (Line 50), I get the MsgBox content pasted at the bottom. Note also that you can set the var Gender to three different things. When gender is male or female, the sentences are capitalized as expected. When gender is "neutral" though, The second letter is getting capitalized. Like "tHey."

Note that the entire middle chunk of code is only used when gender is neutral. Maybe that is effecting the lower regexReplace??

Code: Select all

#SingleInstance
MyEntry = 
(
Pat uses [e]/[m] when describing [m]self.  [e] likes the freedom to express [s] rights.  The choice is [r].{Enter}Then [e] waltzes across the room.{Enter}[e] passes all expectations.{Enter}[e] usually washes [s] hands after using the restroom.{Enter}[e] watches the teacher.{Enter}[e] sits up front and watches the teacher.{Enter}[e] reads well.{Enter}[e] fixes the mistakes on [s] papers.{Enter}[s] goes to the resource room.{Enter}[e] studies hard.{Enter}[e] plays in the band.
)

;Gender := "male"
;Gender := "female"
Gender := "neutral"

IfEqual, Gender, male 
{
   varHeShe = he
   varHimHer = him
   varHisHer = his
   varHisHers = his
}
IfEqual, Gender, female
{
   varHeShe = she
   varHimHer = her
   varHisHer = her
   varHisHers = hers
}
IfEqual, Gender, neutral
{
   varHeShe = they
   varHimHer = them
   varHisHer = their
   varHisHers = theirs
}

MyEntry := StrReplace(MyEntry,"[n]",StudentName) ; Makes the replacements.

MyEntry := StrReplace(MyEntry,"[e]",varHeShe) ; Gender pronouns.
MyEntry := StrReplace(MyEntry,"[m]",varHimHer)
MyEntry := StrReplace(MyEntry,"[s]",varHisHer)
MyEntry := StrReplace(MyEntry,"[r]",varHisHers)

IfEqual, Gender, neutral ; This part gets skipped if gender = male or female.
{
	MyEntry := StrReplace(MyEntry,"they is","they are") ; Fix gramar if gender neutral.
	MyEntry := StrReplace(MyEntry,"they has","they have")
	MyEntry := StrReplace(MyEntry,"they was","they were")
	MyEntry := RegExReplace(MyEntry, "U)([Tt]hey\s)(.*?)ies\b", "$1$2y") 
	MyEntry := RegExReplace(MyEntry, "U)([Tt]hey\s)(.*?)([s|z|sh|ch|x|o])es\b", "$1$2$3") 
	MyEntry := RegExReplace(MyEntry, "U)([Tt]hey\s)(.*?)s\b", "$1$2")
}

MyEntry := RegExReplace(MyEntry, "^\w|(?:\.|:)[\s|\R|\Q{Enter}\E]+\K\w", "$U0") ; Makes sure most sentences are capitalized.

MyEntry := StrReplace(MyEntry,"{Enter}","`n") ; This line was added for the forum post.

MsgBox, TEXT SENT:`n`n%MyEntry%
ExitApp
Thoughts?
TEXT SENT:
Pat uses they/them when describing themself. tHey likes the freedom to express their rights. The choice is theirs.
Then they waltzes across the room.
tHey passes all expectations.
tHey usually washes their hands after using the restroom.
tHey watches the teacher.
tHey sits up front and watches the teacher.
tHey reads well.
tHey fixes the mistakes on their papers.
tHeir go to the resource room.
tHey study hard.
tHey play in the band.
EDIT: I just noticed that this U)([Tt]hey\s)(.*?)([s|z|sh|ch|x|o])es\b is not catching all the things it's supposed to either. :facepalm:
ste(phen|ve) kunkel

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Regex capitalization glitch.  Topic is solved

Post by mikeyww » 23 Oct 2021, 16:28

It looks like you are trying to use alternatives inside a character class, but that would be invalid syntax for regex. As far as I know, \R is also invalid in a character class. Some of the forum's other posts about capitalizing sentences might have code that you can adapt.

Explained: Classes of characters

User avatar
kunkel321
Posts: 1049
Joined: 30 Nov 2015, 21:19

Re: Regex capitalization glitch.

Post by kunkel321 » 24 Oct 2021, 14:27

You were right, Mike. Using parentheses for my alternations fixed the regexes mostly.
Thanks!
ste(phen|ve) kunkel

Post Reply

Return to “Ask for Help (v1)”