RegEx question for Trados Studio
Thread poster: MikeTrans
MikeTrans
Germany
Local time: 01:29
Italian to German
+ ...
Dec 4, 2016

Hello,
It's very useful to use Regular Expressions in the Find & Replace, as well as in the filters of Studio. I have this generic problem and no response after consulting my various RegEx documentations:

In the 'Find' row of Find & Replace, I would like to enter a RegEx for matching the pure position in the segment without matching any character. Is this possible?

For example, in order to insert something at the start of my target segment, I can easily type what I want to insert in the Replace box, but what RegEx should I insert in the Find box for matching the start of the segment but WITHOUT matching the first character (which would otherwise be replaced)?

^ = start of line; will match the first letter/digit/non-word character of the segment, but I don't want to replace this one, I want any content in the 'Replace' box inserted BEFORE it!

I hope my question is clear enough for you to see what I mean ..:)

Thank you very much,
Mike


Direct link Reply with quote
 

Dan Lucas  Identity Verified
United Kingdom
Local time: 00:29
Member (2014)
Japanese to English
Insertion is possible Dec 4, 2016

MikeTrans wrote:
^ = start of line; will match the first letter/digit/non-word character of the segment, but I don't want to replace this one, I want any content in the 'Replace' box inserted BEFORE it!
I hope my question is clear enough for you to see what I mean ..:)

To be honest it's not very clear, but it sounds like you want to insert something. One way to do it is with a capturing group.

Find:
^(.*)
Replace:
-inserted-text-${1}

Regards
Dan


Direct link Reply with quote
 

NeoAtlas
Spain
Local time: 01:29
English to Spanish
+ ...
If I understand correctly… Dec 4, 2016

You can use this regex:

.something

It'll find “something” if there is anything before.

… Jesús Prieto …


Direct link Reply with quote
 
MikeTrans
Germany
Local time: 01:29
Italian to German
+ ...
TOPIC STARTER
Thank you very much... Dec 4, 2016

...Dan Lucas and NeoAtlas to give me some possibilities to work with.
I know my questions were neither simple nor clear, I excuse me for this. The keyword is: 'Insert' into a segment instead of replacing something. A simple example is: Insert something at cursor position 5 after segment start, and without replacing what's left or right of the cursor position, and whatever is left or right (not a constant).

The 'Wildcard' .* should be useful to do what I want, also the exclusion pattern [^...] which i have successfully used to delete parts of a segment.

For me, RegEx is an eternal trial & error procedure... But I'm confident.

Thank you for the assistance,
Mike

[Edited at 2016-12-04 15:28 GMT]


Direct link Reply with quote
 
MikeTrans
Germany
Local time: 01:29
Italian to German
+ ...
TOPIC STARTER
@Dan, Dec 4, 2016

Great, you command works perfectly to insert a text at the start of segment!
Could you tell me what the ${1} does?
Taken separately, $ is the end of line and {1} means you want exactly 1 occurence. So ${1} would instruct to go after the end of line and insert 1 time at the start of next line, correct?

Very useful, thanks very much!
Mike


Direct link Reply with quote
 

Nora Diaz  Identity Verified
Mexico
Local time: 17:29
Member (2002)
English to Spanish
+ ...
Inserting something Dec 4, 2016

Hi Mike,

I'm not sure I'm understanding exactly what you need, but here's my attempt:

Say you have a segment with a string like 12345678910, and you want to insert something after the fourth character from the start of the segment, or "4", then you could enter this in the Search box:

^(.{4})

and this in your Replace box:
$1YOURINSERTION

where, of course, YOURINSERTION is what you want to insert.

The result would be

1234YOURINSERTION5678910


Direct link Reply with quote
 
MikeTrans
Germany
Local time: 01:29
Italian to German
+ ...
TOPIC STARTER
Hello Nora, Dec 4, 2016

[EDIT]
again I have to excuse my confused description of what I want. Your example works !! I have now to figure out how to change Dan's suggestion to make it work inserting content at the end of a segment. I think I can figure this out, I will have to play trial and error...

Inserting at the start, at the end, or inserting after a specific content in the middle of a segment: these are procedures I want to carry out before I start translating. The purpose is: not having to copy such content manually every time for each individual segment.

Thank you very much,
Mike

[Edited at 2016-12-04 17:07 GMT]


Direct link Reply with quote
 

Dan Lucas  Identity Verified
United Kingdom
Local time: 00:29
Member (2014)
Japanese to English
Insertions redux Dec 4, 2016

MikeTrans wrote:
Insert something at cursor position 5 after segment start, and without replacing what's left or right of the cursor position, and whatever is left or right (not a constant).

Yes, that's what capturing groups and backreferences are for. The regex I used earlier has been tested in Studio and it works fine on my system. I suggest you experiment with it.

By using two capturing groups you can perform insertions in the middle of a segment. Say for example you wanted to insert something after the fifth character. Define the first group as the first five characters and the second group as everything after the first five characters. Then when replacing, simply add the text you want inserted between the two groups. The existing text will not be destroyed, but the new text will be inserted.

Find:
^(\S{5})(.*)
Replace:
${1}-text-to-insert-${2}

If you use or want to use regexes, I advise you to buy RegexBuddy for 30 euro. You'll save hours of time and make yourself more efficient.

Dan


Direct link Reply with quote
 

Dan Lucas  Identity Verified
United Kingdom
Local time: 00:29
Member (2014)
Japanese to English
Backreference Dec 4, 2016

MikeTrans wrote:
Could you tell me what the ${1} does?

As explained in the link I provided in my first post, when you put brackets round text in a regex, that text is "captured" as a numbered capturing group. The content of the first set of brackets goes into group 1, the content of the second set of brackets goes into group 2 and so on. You can use the content in these groups by referring to it with the ${n} notation, where n is the group number. See my other post for an example.

To insert text at the end of the segment, experiment with the $ text anchor. I haven't tested it, but try the following.

Find:
(.*)$
Replace:
${1}-text-to-be-inserted

That should insert text at the end.

Dan


Direct link Reply with quote
 
MikeTrans
Germany
Local time: 01:29
Italian to German
+ ...
TOPIC STARTER
Interesting, I must consider this... Dec 4, 2016

Dan Lucas wrote:

If you use or want to use regexes, I advise you to buy RegexBuddy for 30 euro. You'll save hours of time and make yourself more efficient.

Dan


Thank you Dan for this advice. I will have to go this route I think, I'm generally a curious person that wants to solve puzzles or similar problems, but there are times where I cannot afford to spend so much time for it!

Mike


Direct link Reply with quote
 

Dan Lucas  Identity Verified
United Kingdom
Local time: 00:29
Member (2014)
Japanese to English
The value of your own time Dec 4, 2016

MikeTrans wrote:
but there are times where I cannot afford to spend so much time for it!

Indeed. I am happy to invest in tools if they save me time. If your time is worth, say 40 euro an hour, then if RegexBuddy saves you one hour it will have more than paid for itself.

Dan


Direct link Reply with quote
 

NeoAtlas
Spain
Local time: 01:29
English to Spanish
+ ...
I didn't know… Dec 5, 2016

I didn't know that ${1}
has the same effect as
$1

Thanks, Dan!


Direct link Reply with quote
 

Dan Lucas  Identity Verified
United Kingdom
Local time: 00:29
Member (2014)
Japanese to English
Specific issue Dec 5, 2016

NeoAtlas wrote:
I didn't know that ${1}has the same effect as $1

It's a feature of the regex "dialect" used by Studio (which is the C# .Net version). There's an awful lot of variation between different flavours of regexes. What works in one piece of software may not work at all in another.

Dan


Direct link Reply with quote
 

Nora Diaz  Identity Verified
Mexico
Local time: 17:29
Member (2002)
English to Spanish
+ ...
Me neither Dec 5, 2016

NeoAtlas wrote:

I didn't know that ${1}
has the same effect as
$1

Thanks, Dan!



I didn't know this either!

Regarding Regex Buddy, I support Dan's suggestion 100%. I've been using it to learn about regular expressions since Paul Filkin recommended it in one of his series of regex posts and have found it very helpful to test regex matches and replacements. The tutorial at the Regex Buddy developer's website, http://www.regular-expressions.info/tutorial.html, is a great source of information about regex as well.


Direct link Reply with quote
 
MikeTrans
Germany
Local time: 01:29
Italian to German
+ ...
TOPIC STARTER
Thank you all for your responses and advices! Dec 5, 2016

For completness, I just want to report that Dan's solution for inserting content at the end (see above) works perfectly too, the condition is that the segment must not be empty.

I found a serie of interesting pages describing RegEx in detail. Generally they list all immaginable commands sorted by options and symbols. But it's their combination in special situations that is tricky. I have built my own list for maintaining translation memories (with Olifant) in the past, but for the translation work in Trados, I think I will build a new list from scratch depending on the procedures that I mostly use.
All your kind suggestions will sureley be included!

Thank you and best greetings,
Mike


[Edited at 2016-12-05 15:45 GMT]


Direct link Reply with quote
 


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


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

RegEx question for Trados Studio

Advanced search







SDL MultiTerm 2017
Guarantee a unified, consistent and high-quality translation with terminology software by the industry leaders.

SDL MultiTerm 2017 allows translators to create one central location to store and manage multilingual terminology, and with SDL MultiTerm Extract 2017 you can automatically create term lists from your existing documentation to save time.

More info »
Déjà Vu X3
Try it, Love it

Find out why Déjà Vu is today the most flexible, customizable and user-friendly tool on the market. See the brand new features in action: *Completely redesigned user interface *Live Preview *Inline spell checking *Inline

More info »



Forums
  • All of ProZ.com
  • Term search
  • Jobs
  • Forums
  • Multiple search