Regular expressions and replacing strings of text
Initiator des Themas: l3goman (X)
l3goman (X)
l3goman (X)
Englisch > Spanisch
Aug 22, 2014

Hi everyone,

I am currently studying the use of regular expressions and their use, but I am stuck on the "replace" part of the process. Can I also use regular expressions to replace whatever strings i have found?

For example, changing all the commas in numbers for periods or non-breaking spaces:
-253,000 to 253.000 or 253 000

I can fin the occurrences of these numbers with the following regular expression:

([0-9]{3}),([0-9]{3}) - This re
... See more
Hi everyone,

I am currently studying the use of regular expressions and their use, but I am stuck on the "replace" part of the process. Can I also use regular expressions to replace whatever strings i have found?

For example, changing all the commas in numbers for periods or non-breaking spaces:
-253,000 to 253.000 or 253 000

I can fin the occurrences of these numbers with the following regular expression:

([0-9]{3}),([0-9]{3}) - This regex would theoretically find all numbers from 100,000 to 999,999

The problema I have is that when I try to replace it with, for example, ([0-9]{3}).([0-9]{3}) (replacing the comma with a period or a space), the numbers get replaced by the actual regex and not for what it represents.

Problem: 253,000 gets replaced by ([0-9]{3}).([0-9]{3}) and not 253.000.

Is it actually possible to do this or is it just to find strings of text? Am i doing anything wrong?

Thanks in advance

[Edited at 2014-08-22 23:22 GMT]
Collapse


 
Rolf Keller
Rolf Keller
Deutschland
Local time: 20:49
Englisch > Deutsch
Use Google for Regex examples Aug 24, 2014

l3goman wrote:

Can I also use regular expressions to replace whatever strings i have found?

Yes.

Am i doing anything wrong?

Yes.

1 – you didn't mention the software environment resp the regex dialect you use. There are several dialects.

2 – A replace operation needs two separate strings ('patterns'), the first one is used ONLY for "find", the second one is used ONLY for "replace".

Example (may or may not fit for your software):
Find: ([0-9]{3}),([0-9]{3})
Replace: \1.\2

Note: \1 and \2 are backreferences to the first resp last part of the Find string. Without backreferences you can't achieve what you want.

Use Google for examples that fit to your software.


 
l3goman (X)
l3goman (X)
Englisch > Spanisch
THEMENSTARTER
Problem solved Aug 24, 2014

I forgot to mention I'm using Word 2013. Thank you for your help, I was able to solve the problem

 


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


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

Regular expressions and replacing strings of text







Protemos translation business management system
Create your account in minutes, and start working! 3-month trial for agencies, and free for freelancers!

The system lets you keep client/vendor database, with contacts and rates, manage projects and assign jobs to vendors, issue invoices, track payments, store and manage project files, generate business reports on turnover profit per client/manager etc.

More info »
Anycount & Translation Office 3000
Translation Office 3000

Translation Office 3000 is an advanced accounting tool for freelance translators and small agencies. TO3000 easily and seamlessly integrates with the business life of professional freelance translators.

More info »