I need help with a simple regex expression
Thread poster: hieuthao

hieuthao
Vietnamese to English
Jul 16, 2014

I'm working in a document that Trados converted from pdf, and throughout the document the number 1 was replaced with the lower case letter l. For example, l960 instead of 1960. So I want to use regex to replace the "l"s with "1"s. I have read online about regex, and as far as I can see I am doing it right, but it doesn't work.

The search expression is easy: (l)([0-9]) or just l[0-9].

But I can't get the replace expression. I've tried things like %11%2[0-9] or \11\2[0-9]. No matter what I try, it just replaces the entire expression instead of replacing just the "l" and leaving the rest of the number alone.

Can anyone help me???


Direct link Reply with quote
 

NeoAtlas
Spain
Local time: 02:49
English to Spanish
+ ...
Regex anser Jul 16, 2014

Search pattern:
l(\d)

Replace pattern:
1$1

Don't forget to select Use "Regular expressions" in the list box below

Regrads,

... Jesús Prieto ...


Direct link Reply with quote
 

Philip Lees  Identity Verified
Greece
Local time: 03:49
Member (2008)
Greek to English
Watch out for the case Jul 16, 2014

hieuthao wrote:

I'm working in a document that Trados converted from pdf, and throughout the document the number 1 was replaced with the lower case letter l. For example, l960 instead of 1960. So I want to use regex to replace the "l"s with "1"s. I have read online about regex, and as far as I can see I am doing it right, but it doesn't work.

The search expression is easy: (l)([0-9]) or just l[0-9].

But I can't get the replace expression. I've tried things like %11%2[0-9] or \11\2[0-9]. No matter what I try, it just replaces the entire expression instead of replacing just the "l" and leaving the rest of the number alone.

Can anyone help me???


Your second search pattern looks nearly right, but you need to capture the number: l([0-9])

The replace pattern suggested by Jesús also looks right.

You refer to "the lower case letter l, but "I" is upper case, not lower. Do you mean "i"? Regexes are usually case-sensitive, unless you tell them not to be.

[Edited at 2014-07-16 12:07 GMT]


Direct link Reply with quote
 

hieuthao
Vietnamese to English
TOPIC STARTER
Thanks, it worked Jul 16, 2014

Thanks Jesus, that worked beautifully, although I have no idea why.

Maybe I need to find a class. The resources I've read online for regex don't seem to be very helpful!


Direct link Reply with quote
 

NeoAtlas
Spain
Local time: 02:49
English to Spanish
+ ...
Interesting Links about Regex Jul 16, 2014

hieuthao wrote:

Thanks Jesus, that worked beautifully, although I have no idea why.

Maybe I need to find a class. The resources I've read online for regex don't seem to be very helpful!


About the Seacrh pattern:
l(\d)

\d matches any digit. It's absolutely the same as the pattern [0-9] you wrote in your post


About the Replace pattern:
1$1

The first "1" means that the wrong "l" will be replaced by the correct "1".
Then the "$1" states to replace the text matched by the first parenthesis of the Search pattern, i.e, the first digit, by itself, with no change.


I'm attaching some links with useful information to get started with regex. There are also some tools than can help you test the regex patterns:

https://groups.yahoo.com/neo/groups/TW_users/conversations/messages/67339
http://www.proz.com/forum/sdl_trados_support/266263-regular_expression_for_numbers.html
http://www.rexegg.com/regex-uses.html
http://www.regexper.com
http://www.regexhero.net/tester/
http://www.regular-expressions.info/
http://www.regexbuddy.com/demo.html
http://www.freeformatter.com/regex-tester.html




Also, there are some resources in the blog of Paul Filkin, in case you didn't know it:
http://multifarious.filkin.com/2012/07/01/studiogems1/
http://multifarious.filkin.com/2012/08/24/regex-pt1/
http://multifarious.filkin.com/2012/08/29/regex-pt2/
http://multifarious.filkin.com/2012/09/13/regex-pt3/
http://multifarious.filkin.com/2013/01/18/dogs-and-cats-regular-expressions-part-4/
http://multifarious.filkin.com/2013/12/14/firstdayofxmas/
http://multifarious.filkin.com/2013/07/30/xpath/





Regular expressions is a powerful way to execute many interesting operations under Studio: Search & replace like you needed, setting the QA Checker, setting segmentation rules, filtering the text strings in the Editor, customizing a new filetype…, so I'd strongly recommend every Studio user to know the basis of RegEx. The very little I know of RegEx really helps me a lot.

Sure these links help you get more than a basic understanding of RegEx.

Regards,

... Jesús Prieto ...


Direct link Reply with quote
 

hieuthao
Vietnamese to English
TOPIC STARTER
Thanks for the resources Jul 19, 2014

I will definitely read through them and hopefully will be able to do this myself next time!

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 »

I need help with a simple regex expression

Advanced search







Wordfast Pro
Translation Memory Software for Any Platform

Exclusive discount for ProZ.com users! Save over 13% when purchasing Wordfast Pro through ProZ.com. Wordfast is the world's #1 provider of platform-independent Translation Memory software. Consistently ranked the most user-friendly and highest value

More info »
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 »



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