Pages in topic:   [1 2] >
Trados 2019: regex fails in Find and Replace
Thread poster: Denis Fesik
Denis Fesik
Denis Fesik
Local time: 20:58
English to Russian
+ ...
Oct 22, 2021

Hi! Could anyone give me a clue about why none of the regex find and replace guidelines I know of can help me with my find and replace in that I put some regex in parentheses to denote a group and then that group gets replaced with $? In memoQ, the same trick works as intended. The thing in the "Find what" gets found throughout the text, so the syntax is supposed to be correct, but somehow, the placeholders in the "Replace with" don't get mapped to the groups in the "Find what" (their numbers be... See more
Hi! Could anyone give me a clue about why none of the regex find and replace guidelines I know of can help me with my find and replace in that I put some regex in parentheses to denote a group and then that group gets replaced with $? In memoQ, the same trick works as intended. The thing in the "Find what" gets found throughout the text, so the syntax is supposed to be correct, but somehow, the placeholders in the "Replace with" don't get mapped to the groups in the "Find what" (their numbers being the same). Maybe Trados 2019 does something differently? I tried using the reverse slash instead of the dollar sign (read it in some tutorial) but that would produce an error every timeCollapse


 
Stepan Konev
Stepan Konev  Identity Verified
Russian Federation
Local time: 20:58
English to Russian
Show your regex please Oct 22, 2021

Which regex are you trying to use? What is $? ?
$1, $2... works in Trados F&R feature the same way as anywhere else.

[Edited at 2021-10-22 14:56 GMT]


 
Denis Fesik
Denis Fesik
Local time: 20:58
English to Russian
+ ...
TOPIC STARTER
Tried different ones Oct 22, 2021

Like ([0-9]{3}) for 3-digit numbers where I wanted to convert two such numbers with a hyphen in between them to the "from-to" format, but this is not the only time $1 and $2 (from $1 to $2 in this case) have failed me, they fail me every time (the ? sign got there by mistake, I should have escaped some characters that seem to be illegal here)

[Edited at 2021-10-22 14:32 GMT]


 
Stepan Konev
Stepan Konev  Identity Verified
Russian Federation
Local time: 20:58
English to Russian
Make sure to check the Use regex box Oct 22, 2021

I have tried to replace ([0-9]{3}) with $1 and it worked fine.
I can think of two things here: first you replace 3 digits with exactly the same 3 digits. So visually nothing happens because 123 is replaced with 123.
Second, do you check the box for regex?
2021-10-22_180103
Denis Fesik wrote:
Like ([0-9]{3}) for 3-digit numbers where I wanted to convert two such numbers with a hyphen in between them to the "from-to" format
This is not clear to me. Could you please give a specific example of what you are after?

[Edited at 2021-10-22 15:06 GMT]


 
Denis Fesik
Denis Fesik
Local time: 20:58
English to Russian
+ ...
TOPIC STARTER
I use the box, doesn't work Oct 22, 2021

Sometimes, Trados gets stupid and kills decimals that appear in English (say, in European standards) in the Russian format, i. e. with a comma, by substituting the comma with a non-breaking space even if the first digit is zero (I disabled number recognition but this thing came to me from someone else whose work I'm editing), so I want to fix the problem. I insert the following in the "Find what": "([0-9]{1}) ([0-9]+)" (non-breaking space in between the parens). Then I insert the following in t... See more
Sometimes, Trados gets stupid and kills decimals that appear in English (say, in European standards) in the Russian format, i. e. with a comma, by substituting the comma with a non-breaking space even if the first digit is zero (I disabled number recognition but this thing came to me from someone else whose work I'm editing), so I want to fix the problem. I insert the following in the "Find what": "([0-9]{1}) ([0-9]+)" (non-breaking space in between the parens). Then I insert the following in the "Replace with": "$1,$2" (both insertions are what's within the quotes). Here's what I get in return (copying & pasting from Trados): "$1,$2"Collapse


 
Stepan Konev
Stepan Konev  Identity Verified
Russian Federation
Local time: 20:58
English to Russian
Your regex is ok Oct 22, 2021

Well, I have tried your regex and it works fine again. It replaces nbsp with comma.
How do you type the nbsp character? You can't paste it from MS Word because it converts into a regular space. You need to use an Alt code: press and hold Alt, type 0160 using numpad, release Alt.

[Edited at 2021-10-22 15:59 GMT]


 
Denis Fesik
Denis Fesik
Local time: 20:58
English to Russian
+ ...
TOPIC STARTER
I do the Alt code Oct 22, 2021

Maybe my Trados is broken then (it's on my workplace PC, I prefer to use mQ at home), the problem is not in the find (it finds all I want it to find, and this works in filters too) but in the replace

 
Stepan Konev
Stepan Konev  Identity Verified
Russian Federation
Local time: 20:58
English to Russian
Sounds odd Oct 22, 2021

ezgif.com-gif-maker
Even though your regex is ok too, but maybe you can simplify your regex to ([0-9]) ([0-9]) ? I wonder if it changes anything...


 
Anthony Rudd
Anthony Rudd

Local time: 19:58
German to English
+ ...
Simplified regex Oct 23, 2021

You could further simplify the regex to: (\d)\xa0(\d+)
where \xa0 matches a non-breaking space


 
Denis Fesik
Denis Fesik
Local time: 20:58
English to Russian
+ ...
TOPIC STARTER
Thanks, I know about this format Oct 23, 2021

Didn't know the \xa0 thing though, I'll keep this in mind, it's just that I've always preferred building regex with these brackets. They say, (\w) matches any word, but this didn't work in my case. I had build a regex for 'any number of characters other than a space' and it worked like a charm. In memoQ – because I don't just want to search for things but also to do things with them, and that's where my Trados fails me for some reason

 
Stepan Konev
Stepan Konev  Identity Verified
Russian Federation
Local time: 20:58
English to Russian
Why not put it simple? ([0-9]) ([0-9]) or (\d) (\d) Oct 23, 2021

Both ([0-9]{1}) ([0-9]+) and (\d)\xa0(\d+) work the same way: they replace the first instance only. If you have more than 1 nbsp in a number, you have to run the regex again. Unlike those two regexs, ([0-9]) ([0-9]) do the job with only one run. Why do you need "{1}" which does nothing here? And the quantifier "+" as well.

 
Stepan Konev
Stepan Konev  Identity Verified
Russian Federation
Local time: 20:58
English to Russian
\w Oct 23, 2021

Denis Fesik wrote:
They say, (\w) matches any word
The \w is exactly the same as [a-zA-Z0-9_]. It's not a word, but any one of word characters, or any one of 10 digits, or underbar.

\w+ matches a word (excluding hyphen separated words like 5-day, long-term, etc.).

[Edited at 2021-10-23 16:15 GMT]


 
Denis Fesik
Denis Fesik
Local time: 20:58
English to Russian
+ ...
TOPIC STARTER
My question was not about optimizing regex Oct 24, 2021

Most of the work I do can't be done via regex, and I only started looking into regex capabilities recently. What I mentioned were examples that worked for me in terms of search but not in terms of replace, so I don't understand the aggressive attitude. I'll start thinking of ways in which I can optimize my regex when I learn how to make it work. Something is misconfigured in my Trados, and nothing in this thread so far has given me a clue on how I can configure it properly

 
Stepan Konev
Stepan Konev  Identity Verified
Russian Federation
Local time: 20:58
English to Russian
What is so aggressive in my suggestions? Oct 24, 2021

Denis Fesik wrote:
I don't understand the aggressive attitude
Which of my suggestions was aggressive to you? You expect \w to capture words — I just told you that you can't capture words with \w and suggested you a correct way to capture words. Is it aggressive?

nothing in this thread so far has given me a clue on how I can configure it properly
And hardly you will ever get any clue with this approach. I tried to understand your situation by asking you guiding questions because you don't give any specific information until I ask for it. I had to ask for a specific regex two times before you showed it. You consider it aggressive. Ok.

The problem is not about Trados, I'm afraid.

[Edited at 2021-10-24 21:54 GMT]


 
Anthony Rudd
Anthony Rudd

Local time: 19:58
German to English
+ ...
Regex word metacharacter Oct 25, 2021

Stepan: A minor point, \w is not exactly the same as [a-zA-Z0-9_], but also includes non-English alphabetic characters and digits.

 
Pages in topic:   [1 2] >


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

Trados 2019: regex fails in Find and Replace







CafeTran Espresso
You've never met a CAT tool this clever!

Translate faster & easier, using a sophisticated CAT tool built by a translator / developer. Accept jobs from clients who use Trados, MemoQ, Wordfast & major CAT tools. Download and start using CafeTran Espresso -- for free

Buy now! »
Trados Business Manager Lite
Create customer quotes and invoices from within Trados Studio

Trados Business Manager Lite helps to simplify and speed up some of the daily tasks, such as invoicing and reporting, associated with running your freelance translation business.

More info »