regex using units of measure
Thread poster: Clarisa Moraña

Clarisa Moraña  Identity Verified
Argentina
Local time: 15:59
Member (2002)
English to Spanish
+ ...
Nov 18, 2014

Hi, colleagues

I'm trying to apply the find and replace function using regular expressions for units of measure.
The target is a number followed by the unit of measure, but I need to add a non breaking space in between. Right now, I have the number with the unit in one single word.

Example:

I have 3mm in my target text, and I need to replace to 3(non breaking space)mm
I have 4m in my target text, and I need to replace to 4(non breaking space)m
I have 5cm in my target text, and I need to replace to 5(non breaking space)cm

I start the find and replace search using the following regular expression:
[0-9]{1,}[mm|cm|m]

It works fine, but I don't know what to enter into the REPLACE field to get the results I want.

Kind regards

Clarisa


 

SDL Community  Identity Verified
United Kingdom
Local time: 20:59
English
Probably the easiest way... Nov 18, 2014

... is to first add the back references to your expression so the number and units are remembered:

([0-9]{1,})([mm|cm|m])

So the number would be recalled in the replace with $1 and the unit with $2. But you need to add the non-breaking space, so what I always do here is copy and paste from Word. So put this between the two back references in the replace field like this:

$1 $2

The gap in the middle would be your non-breaking space copied in.

Make sense?

Regards

Paul

[Edited at 2014-11-18 16:37 GMT]


 

Dan Lucas  Identity Verified
United Kingdom
Local time: 19:59
Member (2014)
Japanese to English
More information Nov 18, 2014

SDL Support wrote:
... is to first add the back references to your expression

Paul, what flavour of regex does Studio support? I couldn't find much information in the frankly not very helpful help files. (It may be there, but searching help just seems to throw me back to the SDL help page; would love it to default to offline help...

Dan


 

SDL Community  Identity Verified
United Kingdom
Local time: 20:59
English
Studio uses a .NET flavour for regex Nov 18, 2014

Hi Dan,

After attempting to use the help, seeing what you meant, then recording the experience for our teams I used google!


Probably the easiest way to find an answer!

But we will address the current problem with the online help looping like that.

Regards

Paul


 

Clarisa Moraña  Identity Verified
Argentina
Local time: 15:59
Member (2002)
English to Spanish
+ ...
TOPIC STARTER
Thanks! Nov 18, 2014

I'm not quite sure of what I was doing wrong, but your regex worked seamlessly! Regarding the non breaking space, I inserted one manually from QuickInsert, Editor view, as the MS Word commands weren't working.

Thank you Paul for your prompt reply, as usual!

Clarisa


 

Ruth Wiedekind  Identity Verified
Germany
Local time: 20:59
Member (2004)
Spanish to German
+ ...
Project settings... Nov 19, 2014

Why don't you try:

Project settings -> (actual) language pair -> translation memories -> automatic replacement -> units:
There you can choose the option "always add..."


 

SDL Community  Identity Verified
United Kingdom
Local time: 20:59
English
Help is back... Nov 19, 2014

Dan Lucas wrote:

(It may be there, but searching help just seems to throw me back to the SDL help page; would love it to default to offline help...



Hi Dan,

It seems that we need to reindex the help (we need to do this for every release on the day we release) and this happened yesterday afternoon. So our timing was perfect... I'd not come across this before either so now I know!

I did a quick search in the help now it's back and the first hit contains this information in the fourth paragraph:

Studio uses the .Net syntax for regular expressions.

Regards

Paul


 

Dan Lucas  Identity Verified
United Kingdom
Local time: 19:59
Member (2014)
Japanese to English
Thanks, appreciate the advocacy Nov 19, 2014

SDL Support wrote:
I did a quick search in the help now it's back and the first hit contains this information in the fourth paragraph:
Studio uses the .Net syntax for regular expressions.

A learning experience for everybody involved; how positive!

Thanks
Dan


 

SDL Community  Identity Verified
United Kingdom
Local time: 20:59
English
Good idea! Nov 19, 2014

Ruth Wiedekind wrote:

Why don't you try:

Project settings -> (actual) language pair -> translation memories -> automatic replacement -> units:
There you can choose the option "always add..."


Hi Ruth,

Sometimes the obvious is completely obscured by the desire to play with regular expressions... this is what hap{2}en(s) when you $1tart\sto\s lo{2}k\sat\sthemicon_wink.gif

Regards

Paul


 

anamaria bulgariu  Identity Verified
Romania
Local time: 21:59
Member (2007)
English to Romanian
+ ...
Similar but not quite May 29, 2015

This is my first attempt at using RegEx in Trados.

Issue: I have a lot of amounts (with English decimal and thousand separators) followed by the pound sign (£) in the source.
The target should be the amount (with comma for decimals and dot for thousands), followed by a non-breaking space and inevitably the Pound sign.

So... after some reading... the Find and Replace pane should look like this(?):
Find: ([£])([0-9000.0]{1,})
Replace: $2 $1

The result is... no non-breaking space...

What am I doing wrong?

PS: A RegEx for Dummies crash course would be such a great idea right now.


 

Emma Goldsmith  Identity Verified
Spain
Local time: 20:59
Member (2010)
Spanish to English
Non-breaking space code May 29, 2015

anamaria bulgariu wrote:

This is my first attempt at using RegEx in Trados.

Issue: I have a lot of amounts (with English decimal and thousand separators) followed by the pound sign (£) in the source.
The target should be the amount (with comma for decimals and dot for thousands), followed by a non-breaking space and inevitably the Pound sign.

So... after some reading... the Find and Replace pane should look like this(?):
Find: ([£])([0-9000.0]{1,})
Replace: $2 $1


Have a look at this blog post, where I changed 4,000 € to €4,000:
http://signsandsymptomsoftranslation.com/2012/09/19/sp2-updated-release/

Use this code for a non-breaking space:
\u00A0


 

SDL Community  Identity Verified
United Kingdom
Local time: 20:59
English
A little tip for tricky things like this... May 29, 2015

... is to add them in MSWord, which we all know how to do, and then copy paste the character from Word into the regex. You will only see a space, but the correct space will be used.

In addition to the link from Emma this might be useful too:

http://multifarious.filkin.com/tag/regex-tutorial/

Regards

Paul
SDL Community Support


 


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


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

regex using units of measure

Advanced search







PerfectIt consistency checker
Faster Checking, Greater Accuracy

PerfectIt helps deliver error-free documents. It improves consistency, ensures quality and helps to enforce style guides. It’s a powerful tool for pro users, and comes with the assurance of a 30-day money back guarantee.

More info »
WordFinder Unlimited
For clarity and excellence

WordFinder is the leading dictionary service that gives you the words you want anywhere, anytime. Access 260+ dictionaries from the world's leading dictionary publishers in virtually any device. Find the right word anywhere, anytime - online or offline.

More info »



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