Why doesn't this RegEx return a list?

Hi

this is my search: RegExr: Learn, Build, & Test RegEx

(?<=">)(.{1,12})(?=<\/a><\/li>)

It should return a list of three items:

Purple
Black
Deep Blue

Screenshot 2023-12-04 at 05.08.17

But when I do it in KM it only returns Purple :

From the wiki:

The Search using Regular Expression Action will return the first match it finds in the source string.
In order to make it be a “global” search, you need to put this Action in a For Each Action that uses the [ Substrings Matching in ] Collection. This will loop through all matches found in the source string.
This is often indicated in other tools by the /g modifier.

So you could do something like this:

Regex return multiple matches.kmmacros (4.7 KB)

Macro image

1 Like

From the full source of the HTML you may be able to get your match list more simply from an XPATH expression like //a/text()

See, for example:

1 Like

I would love to be able to do it this way but it's beyond my abilities. I will however carefully read over what you've linked to see if I can figure it out!

(Yes, the RegEx way is a rather clunky way of doing it lol)

I do indeed want to extract all the //a/text()but I don't know / understand XPATH despite having watched some tutorial videos on YouTube.

Update: i've read through your linked example but alas all the code just confuses my simple mind.

I really appreciate your answer -- this has been a real head scratcher for me.