regex help needed

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

regex help needed

Post by newcod3r » 12 Feb 2024, 21:23

I have 3 conflicting regex match and spent days trying to de-conflict but to no avail.

Code: Select all

if RegExMatch(clip, "i)(¥|RMB|CNY)\s?([0-9.,]+)", M) { ; case 1 

if RegExMatch(clip, "i)(\bRM\b|MYR)?\s?([0-9.,]+)", M) {  ; case 2

	if (RegExMatch(clip, "^\s?\d{4}\s?$")) {  ; case 3
    BirthYear := clip
    if (BirthYear >= 1900 && BirthYear <= 2022) {
test cases are as follows:
; case 1
RMB25
RMB 25
25RMB
25 RMB
25 CNY

; case 2
RM25
RM 25
25RM
25 RM

; case 3
1999
2000
2021

Even though I already inserted \b, 25RMB still goes to the 2ⁿᵈ match, and even 1999 also goes to 2ⁿᵈ match. how do I deconflict these 3?
Last edited by newcod3r on 12 Feb 2024, 22:08, edited 1 time in total.

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

Re: regex help needed

Post by mikeyww » 12 Feb 2024, 21:32

Hello,

I find responding to this difficult if you are not going to describe your goal or the desired effect or output. Simply handing the reader a bunch of input strings does not seem to get anywhere.

newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

Re: regex help needed

Post by newcod3r » 12 Feb 2024, 21:35

mikeyww wrote:
12 Feb 2024, 21:32
Hello,

I find responding to this difficult if you are not going to describe your goal or the desired effect or output. Simply handing the reader a bunch of input strings does not seem to get anywhere.
I gave the intended output for the 3 corresponding regexmatches already. the problem now is regexmatch 2 seems to match ALL my test cases.
the first 2 are for currency conversion, and the 3ʳᵈ is simply for a valid birth year.

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

Re: regex help needed

Post by mikeyww » 12 Feb 2024, 21:41

In this case, I am not following your descriptions. I'll let others respond as they may have a better understanding of what you wrote.

newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

Re: regex help needed

Post by newcod3r » 12 Feb 2024, 22:08

I updated the formatting / description. not sure if it's better now?

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

Re: regex help needed

Post by mikeyww » 12 Feb 2024, 22:56

Thank you, but I cannot determine anything definite from the post. It is just a mysterious listing-- unclear of the goal, what you are showing, and what you want to happen. That is just my take on it.

Post Reply

Return to “Ask for Help (v1)”