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: 23:56
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: 00:56
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: 23:56
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







memoQ translator pro
Kilgray's memoQ is the world's fastest developing integrated localization & translation environment rendering you more productive and efficient.

With our advanced file filters, unlimited language and advanced file support, memoQ translator pro has been designed for translators and reviewers who work on their own, with other translators or in team-based translation projects.

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