Difference between revisions of "Useful regular expressions (Regex)"

From Wordfast Wiki
Jump to: navigation, search
Line 1: Line 1:
 
A regular expression (regex or regexp) is a sequence of characters that define a search pattern. They can be very helpful for filtering out segments in the TXLF Editor or for find/replace operations. Check out [https://en.wikipedia.org/wiki/Regular_expression#Basic_concepts this article] for a more detailed explanation of the history of regular expressions and how they work.
 
A regular expression (regex or regexp) is a sequence of characters that define a search pattern. They can be very helpful for filtering out segments in the TXLF Editor or for find/replace operations. Check out [https://en.wikipedia.org/wiki/Regular_expression#Basic_concepts this article] for a more detailed explanation of the history of regular expressions and how they work.
  
Below are a few examples of useful regex. Make sure to tick the regex box accordingly:
+
Below are a few examples of useful regex. Make sure to tick the regex box accordingly.
 +
 
 +
__TOC__
  
 
==Hide all number-only segments==
 
==Hide all number-only segments==
Line 22: Line 24:
 
2. Find , and replace with .
 
2. Find , and replace with .
 
3. Find DUMMY and replace with ,
 
3. Find DUMMY and replace with ,
 +
 +
 +
-John

Revision as of 19:47, 13 March 2019

A regular expression (regex or regexp) is a sequence of characters that define a search pattern. They can be very helpful for filtering out segments in the TXLF Editor or for find/replace operations. Check out this article for a more detailed explanation of the history of regular expressions and how they work.

Below are a few examples of useful regex. Make sure to tick the regex box accordingly.

Hide all number-only segments

Use the following regex in the segment filtering bar:

^(([0-9][^\n]*[^0-9])|([^0-9][^\n]*[0-9])|([^0-9]?[^\n]*[^0-9]))$

This regex will also hide numbers with punctuation (decimals, etc.)


Show only number-only segments

Use the following regex in the segment filtering bar:

^(?:(?:-|–|(?:(?:\$|€|£)(?:\h)?))?(?:\d{1,3})(?:\h|,|\.|(?:(?:\h)?(?:%|\$|€|£)))?)+$

If you have numbers like 8,675,309.00 that need to be replaced with 8.675.309,00, you can copy all sources to target with the filter applied, then apply a 3-step find and replace: 1. Find . and replace with DUMMY 2. Find , and replace with . 3. Find DUMMY and replace with ,


-John