Why would [\d-]* not exclude numbers with dashes?

In a different thread of this forum (https://community.rws.com/product-groups/trados-portfolio/trados-studio/f/studio/52008/how-to-exclude-include-certain-elements-from-the-source-file-and-therefore-from-the-word-count-in-trados-studio-2022) I excluded numbers with dashes from translation using the embedded content processor for Word files.

To my surprise, [\d-]* did not work, at least the preview returned a blank editor - no segments. [\d+]+ did work. In my eyes, this is a bug.

Screenshot of RegexBuddy with a regex pattern highlighting a number with dashes in a test string.

RegexBuddy warns me: “C# (.NET 2.0–7.0) allows a zero-length match at the position where the previous match ends.”

But a zero-length match should not result in anything being converted into a tag.

Regex101 shows all the zero-length matches:

Screenshot of regex101.com showing multiple zero-length matches highlighted in a test string.

as opposed to

Screenshot of regex101.com with a regex pattern highlighting a number with dashes in a test string.

but IMHO this should not affect the conversion into tags.

(All for .NET 7.0)



Generated Image Alt-Text
[edited by: RWS Community AI at 12:31 PM (GMT 0) on 14 Nov 2024]
emoji
Parents
  •   

    I can only hazard a guess that the reason is that [\d-]* could match absolutely nothing, effectively finding "matches" in places where you might not expect or want them, like between every character in your text or at the start/end of a string.  It really doesn't make sense to do this, and if we did it could lead to some very odd results, so Studio probably doesn't support zero-length matches.

    Notwithstanding that, how do you convert a zero-length match to a tag for embedded content?

      may have a better explanation if I've guessed incorrectly.

    Paul Filkin | RWS

    Design your own training!
    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

    emoji
Reply
  •   

    I can only hazard a guess that the reason is that [\d-]* could match absolutely nothing, effectively finding "matches" in places where you might not expect or want them, like between every character in your text or at the start/end of a string.  It really doesn't make sense to do this, and if we did it could lead to some very odd results, so Studio probably doesn't support zero-length matches.

    Notwithstanding that, how do you convert a zero-length match to a tag for embedded content?

      may have a better explanation if I've guessed incorrectly.

    Paul Filkin | RWS

    Design your own training!
    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

    emoji
Children