Make this Regexreplace case insensitive

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Rikk03
Posts: 192
Joined: 12 Oct 2020, 02:44

Make this Regexreplace case insensitive

18 Oct 2020, 14:40

I need the below function Regexreplace to be case insensitive and it's driving me nuts. I found it here https://autohotkey.com/board/topic/117421-count-how-many-times-a-word-appears-and-store/

Code: Select all

MsgBox % "literal: " 	SubStrCt("1+1 1+2 1+1 111", "1+1")        ; missing paramater #3 for literal matching
. "`nRegEx: " 	SubStrCt("1+1 1+2 1+1 111", "1+1", 1)	; paramater #3 = 1 or true for RegEx matching
Return

SubStrCt(Haystack, String, RegexPattern := false) {
    RegExReplace(Haystack, (RegexPattern ? "" : "\Q") . String . (RegexPattern ? "" : "\E"),, ChrCt) ; Case sensitive!
    Return ChrCt
}
I don't really understand the MsgBox part above. All I really need to do is to return a literal count via function - reliably and from within HTML source code. How / where do I add the i) modifier.

The string is via inputbox OR by variable and I need both to work case-insensitively for literal matching.

Your help would be much appreciated!
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Make this Regexreplace case insensitive

18 Oct 2020, 14:49

I'm not sure what you are trying to do, but it would normally be at the start of the regular expression.

Code: Select all

RegExReplace(Haystack, "i)" (RegexPattern ? "" : "\Q") String (RegexPattern ? "" : "\E"),, ChrCt) ; Case insensitive
Rikk03
Posts: 192
Joined: 12 Oct 2020, 02:44

Re: Make this Regexreplace case insensitive

19 Oct 2020, 02:40

Hello again,

Thankyou the case insensitivity worked, but it was unreliable when called in a loop repetitively. With regards what I am trying to do .... in the URL above, almost exactly what I am after but I need it with case-insensitivity as a function to externalize the count.

I'm open to suggestions?
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Make this Regexreplace case insensitive

19 Oct 2020, 06:32

Sure. My suggestion is to post your script if you would like help with it.
Rikk03
Posts: 192
Joined: 12 Oct 2020, 02:44

Re: Make this Regexreplace case insensitive

19 Oct 2020, 06:42

I got it working!

Thanks though Mike.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: badkarma5150, Spawnova and 298 guests