Search Var using RegEx: cannot find multiple RegExes

I'm trying to create a regular expression that lists all combinations of numbers and uppercase letters, text between square brackets and text between straight double quotes.

The regular expression works on regex101 but I cannot get it to work in KM.

Result at regex101:

Result in KM:
Image-000106

The macro:


List non-translatables.kmmacros (6.6 KB)

As in matches ?

Any context for the problem that you hope to solve ?

Not sure what you mean by “as in matches”. Regarding the context: I want to collect all non-translatables (invariants) in every source segment and to be able to insert them in the corresponding target segment.

On second thought: I guess that I cannot combine regexes with pipes. I’ll have to place each regex in a separate Search action.

I guess.

Edit: Yep, that works.

Demo:

Image-000108

You can do this, and your macro was doing it, but you were, I believe, overcomplicating the loop. Your Local_sourceSegment is extracting all the right matches, so you don't need to regex the stuff again within the loop: You have all the substrings, so you just need to assemble them.

Unless I'm missing something about the objective, this seems to work perfectly:

List non-translatables - modified.kmmacros (4.0 KB)

That generates this:

That was the objective, right?

-rob.

1 Like

Remember that, unlike default regex101 patterns, the KM "Search using Regular Expression" action only returns the first match. That's why you need to use a "For Each" loop or similar, nothing to do with "pipes".

If you want to match something "two or more times", try {2,} for "at least two and as many as possible, with no upper limit":

([A-Z0-9]{2,})|\[.*?\]|\".*?\"

It doesn't change the logic in your pattern, but might make it a little more readable (and it's a tad more efficient).

1 Like

Thank you all for your help.

Possible improvements:

  1. List the non-translatables in the Prompt with List in the same order as in the source segment.
  2. Remove each non-translatable from the List after insertion (unless it occurs more than one time in the source segment).

Uncheck the "Sort Entries" option in the gear menu for the Prompt With List action.

You'd need the Prompt With List in a repeat loop, where you remove a row from the variable each time it's pasted, then presents the list again until there are no more lines in the variable. I don't have the time to dig into that, though, but it should be doable.

-rob.

1 Like

Solved it in another way: remove any inserted non-translatable from the sourceSegment variable. The layman’s approach:)