Returning multiple Regular Expression matches

If you are experiencing problems with "Everything", post here for assistance.
Post Reply
klark1kent
Posts: 21
Joined: Thu Aug 11, 2022 1:26 am

Returning multiple Regular Expression matches

Post by klark1kent »

I have to be missing something - Not understanding why I can't get this regex match to return each instance of the match:

Code: Select all

twrp_3.0.1_v10 (2016_07_16 00_50_42 UTC) (2022_01_31 02_32_11 UTC) regex:name:(\d{4}\_\d{2}\_\d{2})
I only included the file name to narrow down the search result to take the screenshot. In this case I have the date string that should match twice. I've added the regex match columns for 0, 1, 2 and Regex 1-9 just in case.

Each method solely returns the first match.
image.png
image.png (46.31 KiB) Viewed 433 times

I've even tried using REGEX_MATCH, which only shows 1 match.

Code: Select all

twrp_3.0.1_v10 (2016_07_16 00_50_42 UTC) (2022_01_31 02_32_11 UTC) a=REGEX_MATCH($Name:,"\d{4}\_\d{2}\_\d{2}") add-column:a
image.png
image.png (52.1 KiB) Viewed 433 times

And REGEX_EXTRACT

Code: Select all

twrp_3.0.1_v10 (2016_07_16 00_50_42 UTC) (2022_01_31 02_32_11 UTC) a=REGEX_EXTRACT($Name:,"\d{4}\_\d{2}\_\d{2}") add-column:a
image.png
image.png (54.99 KiB) Viewed 433 times
void
Developer
Posts: 17152
Joined: Fri Oct 16, 2009 11:31 pm

Re: Returning multiple Regular Expression matches

Post by void »

Are you trying to capture the year, month and day in separate groups?

-If so, please try:

regex:name:(\d{4})\_(\d{2})\_(\d{2})


( ) = define a capture group.



Only the first occurrence is matched by default.
Please try the global: search modifier to match all occurrences:

global:regex:name:(\d{4}\_\d{2}\_\d{2})


REGEX_MATCH() and REGEX_EXTRACT() do not support the global modifier. (PCRE doesn't have a global modifier :( )
klark1kent
Posts: 21
Joined: Thu Aug 11, 2022 1:26 am

Re: Returning multiple Regular Expression matches

Post by klark1kent »

Ah okay I had used parenthesis for capture groups but that also wasn't working, the part I was missing was the global flag. thanks
klark1kent
Posts: 21
Joined: Thu Aug 11, 2022 1:26 am

Re: Returning multiple Regular Expression matches

Post by klark1kent »

Confirming this worked as expected for anyone that comes across this post later.

image.png
image.png (46.45 KiB) Viewed 371 times
Post Reply