[Suggestion:] v in RegExMatch('x','y',&v) should return 0 or false

Propose new features and changes
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

[Suggestion:] v in RegExMatch('x','y',&v) should return 0 or false

19 Jan 2024, 23:51

I wish v in RegExMatch('x','y',&v) to be set to 0/false rather than "", when match is not found.

See these code below:
<code a:>

Code: Select all

	
	;(1) Match is not found, and v will be ""
	RegExMatch('x','y',&v) 

 	;(2)A Match is found, and both will be a matchObj in v this time, and v[] is ""
	RegExMatch('x','y?',&v)
	,RegExMatch('x',"",&v)
<code b:>

Code: Select all

	;(1) A subPattern is found, and v['c'] is ""
	;It's the with v[] in <code a>.  It's right.
	RegExMatch('x','(?<c>y?)',&v)
	,OutputDebug(v['c'])

	;(2) SubPattern is not found, but v['c'] is also ""
	;Both results are the same, this time.
	;This is inconsist with <code a> where both results are different.
	;It is not reasonable.  
	; I think v['c'] is better to return 0 this time.
	RegExMatch('x','(?<c>y)|.*',&v)
	,OutputDebug(v['c'])

	;(3) SubPattern name is not found and it will return unset.
	;At least, I wish v['f'] would return unset, just like v.f??XXX
	RegExMatch('x','(?<c>y)|.*',&v)
	;,OutputDebug(v['f'])
I wish both v in <code a> and v['c'] in <code b> would return 0, when match is not found.

By the way, the suggestion is backward compatible. Because both "" and 0 works equally for an If keyword.
Last edited by V2User on 20 Jan 2024, 07:03, edited 1 time in total.
just me
Posts: 9466
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Suggestion:] v in RegExMatch('x','y',&v) should return 0 or false

20 Jan 2024, 04:02

V2User wrote: By the way, the suggestion is backward compatible. Because both "" and 0 works equally for a If keyword.
So why should it be changed?
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: [Suggestion:] v in RegExMatch('x','y',&v) should return 0 or false

20 Jan 2024, 06:29

just me wrote:
20 Jan 2024, 04:02
V2User wrote: By the way, the suggestion is backward compatible. Because both "" and 0 works equally for a If keyword.
So why should it be changed?
If it finds a blank String in sub pattern, then returning "" is reasonable.
If it doesn't find in sub pattern, then it might be better to return 0, for distinguishing, I think.
Thereupon, through what it returns, we could know exactly whether it has found or not.
iseahound
Posts: 1447
Joined: 13 Aug 2016, 21:04
Contact:

Re: [Suggestion:] v in RegExMatch('x','y',&v) should return 0 or false

20 Jan 2024, 09:52

Completely agree at how frustrating this is. I'm just using type(c) == RegExMatchInfo for now, but in my opinion an empty array with a default of "" should fix most errors like v[1]. Also Lexikos might make it unset because that should be the default return value for v2.1
just me
Posts: 9466
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Suggestion:] v in RegExMatch('x','y',&v) should return 0 or false

20 Jan 2024, 17:50

V2User wrote: Thereupon, through what it returns, we could know exactly whether it has found or not.

Code: Select all

MsgBox(RegExMatch('x','(?<c>y)|.*',&v))    ; 1
MsgBox(v.Count)                            ; 1
MsgBox(v.Pos["c"])                         ; 0 !!!

V2User wrote: ;At least, I wish v['f'] would return unset, just like v.f??XXX
If no property named "f" exists, it cannot be unset.
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: [Suggestion:] v in RegExMatch('x','y',&v) should return 0 or false

20 Jan 2024, 20:37

Maybe v.f? could return unset in language support. ;)

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 55 guests