Find multiple lines with Search Variable Action

Hi

I am trying to extract information from a price list I have in a variable in KM.
The need is to extract all lines contain different SKUs.

A SKU could be:
BC 1104060

And the price list has lines like:
BC 1102050-25
BC 1102050-50
BC 1104060-25
BC 1104060-100
BC 1110060-25
BC 1110060-50

What I would like is to use the Search Variable Action to extract all lines with at given SKU.
So if I feed the Search Variable BC 1104060 then I would like this in a new variable:
BC 1104060-25
BC 1104060-100

I have tried like this:


But then I only get the first instance.

Does anybody know how to get all instances?

You can loop over the lines:

_[test] Get Lines.kmmacros (4.9 KB)

Or you could delete the non-matching lines:

_[test] Delete Lines via Regex.kmmacros (2.8 KB)

Edit:

If your search string (e.g. BC 1104060) is always at the beginning of the line you can simplify the regex to

(?m)^(?!%Variable%zzzSearchStr%).*\R

Thanks, Tom.

I ended up using the one where it deletes the lines. This is way faster.

I forgot that I could loop over the lines. And I tried it. But my source for searching is also in a loop.
So I ended up with a For Each including a For Each looking at 4.000 lines. And this just took to long.

But the idea with deleting items not found works excellent.

I can share the macro if anyone is interested, but it is very centric to a particular task for a customer, where I am upgrading a product catalogue. And I need to find the new SKUs from a pricelist.

If you think a post has solved your problem you can check the “Problem solved” checkbox at the bottom of the post that solved your problem.

I have just seen a good post by @DanThomas about replacing RegEx-critical special chars in a variable.

If your search variable is always something like BC 1104060 you will not need it. But for other variables it might come in handy:

I haven’t tested the RegEx and it might be necessary to adapt it to the specific variable content. But I think the general idea is clear.

1 Like