tracker issue : CF-3321666

select a category, or use search below
(searches all categories and all time range)
Title:

[regression] Update refind() and deprecate reMatch()

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Adam Cameron / Adam Cameron (Adam Cameron)

Created: 08/30/2012

Components: Language

Versions: 10.0

Failure Type: Non Functioning

Found In Build/Fixed In Build: Final / 294412, 294432

Priority/Frequency: Normal / Unknown

Locale/System: English / Platforms All

Vote Count: 2

Listed in the version 2016.0.0.297996 Issues Fixed doc
Verification notes: verified_fixed on August 23, 2017 using build 2016.0.01.298513
There's currently a gap in CF's regex finding.  reFind() will return subexpressions, but only return one match.  reMatch() returns all matches, but no sub expressions.

I recommend updating reFind() to take an additional argument, scope, which is "ONE" or "ALL".  This would make it cover all the bases both functions need.

This would then match reMatch() redundant, and as it's merits are... limited (it's not much use if one cannot get subexpressions too)... I suggest just deprecating it.  CF doesn't need both find & match functions which do subsets of the same functionality.

-- 
Adam

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3321666

External Customer Info:
External Company:  
External Customer Name: Adam Cameron.
External Customer Email:  
External Test Config: My Hardware and Environment details:

Attachments:

Comments:

Hi Adam, I do recall one of your prior tickets, which seems to have vanished in the new tracker: 73662 said: ----------- It would be really good if reMatch() and reMatchNoCase() could be enhanced to accept a returnsubexpressions parameter, as per reFind(). I guess it would return an array of structs, where the structs are the same composition as that for reFind(). I find it fairly infrequent that I’m dealing with regexes matches in which there are no subexpressions needing to be captured too. ----------- I totally liked that. How about this syntax? REMatch(reg_expression, string[, start[, returnsubexpressions]]) And this result format: {lenPos=[{len=[],pos=[]}], matches=[]} Basically, when returnsubexpressions is true, a struct containing two same-length arrays would be returned. One array would be the matches array that it currently returns. The other array would be the lenpos structs array which you described in 73662. Sound alright? Thanks, -Aaron
Comment by External U.
18208 | September 23, 2012 12:29:13 AM GMT
It is definitely possible to merge the functionality of these two functions as you suggested. In case of ALL, it would return an array of struct, each struct containing LEN, POS and matches. As far as deprecation is considered, I am not sure whether it should be deprecated. I feel reMatch is quite useful since it gives you all the matches which reFind does not. Also, CFML has lots of such functions which are not really required as a separate function. For example - all *NoCase functions. None of them were actually required as the functionality could have been achieved by adding a flag to the other related function. but I guess the philosophy has been to add another function with self explanatory name instead of adding additional arguments to the function.
Comment by Rupesh K.
18209 | May 05, 2014 10:41:06 AM GMT
Hi Rupesh, IMO, refind()'s scope="one" should return {len=[],pos=[],match=[]} And refind()'s scope="all" would return [{len=[],pos=[],match=[]}] I believe this was Adam's idea in a prior PR. Then rematch() could be deprecated. Thanks!, -Aaron
Comment by External U.
18210 | May 05, 2014 06:53:09 PM GMT
Yep. And indeed it's what I said in this very ticket, in the second para. -- Adam
Comment by External U.
18211 | May 06, 2014 02:05:42 AM GMT
Hi Adam, Right, yes, the "one" vs "all". Sorry for repeating that part. The point I was trying to make is that refind()'s result struct should also include a matches array (i.e. the ",match=[]" part). I didn't see that in this ticket, but do recall it was your idea and liked it, so I hoped it could be done but didn't want to take credit. Thanks, -Aaron
Comment by External U.
18212 | May 06, 2014 02:25:26 AM GMT
Oh, that was more directed at Rupesh ;-) -- Adam
Comment by External U.
18213 | May 06, 2014 02:26:39 AM GMT
AH, cool =)
Comment by External U.
18214 | May 06, 2014 02:31:53 AM GMT
wow, just realized I never even voted for this.. +1 =D
Vote by External U.
18221 | May 06, 2014 04:39:57 AM GMT
I agree, reFind should return the pos and len of all matches. At the very least we should be able to set the scope of the search to all.
Vote by External U.
18222 | October 14, 2014 08:41:26 AM GMT
When's this due for release, Rupesh? And can you please clarify what all the actions that have been taken are: a) what's the signature of the function, and an example? b) whether or not the resolution of this has impacted other existing functions c) confirm it's been implemented as a String method as well as just a headless function. You really ought to be providing feedback like this: a) on all tickets; b) without being asked. Cheers. -- Adam
Comment by External U.
18215 | February 03, 2015 01:24:20 AM GMT
+1 to Adam's request. This is key info to know. Thanks!, -Aaron
Comment by External U.
18216 | February 03, 2015 05:58:02 AM GMT
@Awdhesh: I cannot see the change in the latest build. Please let me know if the fix is ready or not.
Comment by Poonam J.
18217 | June 16, 2015 12:13:57 AM GMT
This will now be supported in coldfusion next release. Comments below: a) Signature of the function with example. Added Scope (ALL\ONE) param to "Refind" in-built function to return all the matched substring. "One" is the default value to retain all behavior and when scope defined as "ALL", it would return an array of struct, each struct containing LEN, POS and MATCH. Signature: REFind(reg_expression, string [, start, returnsubexpressions , "ALL/ONE"] ) Example: <cfset strQuery = "ben=nice&maria+bello=cold!&lori+petty=cool" /> <cfset objMatch = REFind ("[a-g]",strQuery,1,true,"ALL") /> b) No impact on other existing functions and is a enhancement to a String method . Marking this as closed->fixed.
Comment by Poonam J.
18218 | June 16, 2015 03:56:31 AM GMT
Added support for old application where for "ONE" scope, it will return an struct which is nott wrapped inside an array.
Comment by Awdhesh K.
18219 | June 22, 2015 02:50:53 AM GMT
Verified this is fixed in CF2016 Update 1 (build 2016.0.01.298513). When "scope" parameter of reFind()/reFindNoCase()/myString.reFind()/myString.reFindNoCase() is "all", then array of Len/Pos/Match struct is returned. When "scope" parameter is "one" (or omitted), then returned Len/Pos/Match struct is not wrapped in an array. Note: This new feature is undocumented. Filed doc bug CF-4199526. Thanks!, -Aaron
Comment by Aaron N.
18220 | August 23, 2017 03:12:51 AM GMT