Documentation Center

Regular expressions examples

These are a few examples of how the QA checker can be used with regular expressions.

A list of examples is available in the QA Checker 3.0 > Regular Expressions settings if you select Action > Examples. Selecting any of the examples will display its details. You can then add the example to your list by selecting Add Item.

If you want to create your own expressions, the following explanations for each condition might help.

Report if both target and source regex patterns match
An error is only reported if the pattern is found in the source and target segment.
Might use to check if a target number had not been localized. For example, if 1.23 had not been translated as 1,23.
RegEx.
  • source - \d\.\d{2}
  • target - \d\.\d{2}
You can also use this to check that financial figures have all been localized. For example, if £12,589 had been translated as £12,589 as opposed to £12.589. This does have limited use however as it only checks the pattern and not the numbers themselves.
RegEx:
  • source - £\d+,\d+
  • target - £\d+,\d+
Report if target matches but not the source
An error is only reported if the pattern is found in just the target segment and not the source segment.
Can be used for checking terminology without a termbase. You can make sure certain words do not get mixed up. This is an English - French example.
RegEx:
Rule #1
  • source - file
  • target - fichier
Rule #2
  • source - database
  • target - base de données
Rule #3
  • source - directory
  • target - répertoire
Report if source matches but not the target
An error is only reported if the pattern is found in just the source segment and not the target segment.
Can be used to check for missing punctuation at the end of a sentence. In this case a period at the end.
RegEx:
  • source - \.$
  • target - \.$
Report if source matches (source check only)
Only the source segments are checked for the pattern and not the target segments. An error is reported if the pattern is found in the source segment.
Could be used to check for content in the source. For example, if the source files contained product codes that had to be changed for a different country based on some lookup table provided as reference material. It's not an automated check but would help to find the segments for manually checking against the reference material. So codes in the source like this for example: GB-DIN-234/12, GB-DIN-329/22 or GB-DIN-912/87.
RegEx:
  • source - GB-DIN-\d{3}/\d{2}
Report if target matches (target check only)
Only the target segments are checked for the pattern and not the source segments. An error is reported if the pattern is found in the target segment.
This is commonly used to check for numbers that do not have a non-breaking space between the number and the unit (based on list of units).
RegEx:
  • target - \d\[^xA0](m|mm|cm|km|V|mV|µV|l|ml|°C|Nm|A|mA|bar|s|ms|kV|Hz|kHz|MHz|t|kg|g|mg|W|kW|MW|Ah|mAh|N|kN|obr|min|µm|μm|µS|Pa|MPa|kPa|hPa|mbar|µF|dB|gal|µs|Nl|lux)\b
Report if both source and target match but with a different count
An error is only reported if the number of patterns found in the source and target segments is different. For example, when 'RWS' appears twice in the source, it should also appear twice in the target.
RegEx:
  • source - \bRWS\b
  • target - \bRWS\b
Grouped search expression - report if source matches but not target
You can check exactly what you found in the source and make sure it validates positively or negatively against the target. While the previous checks look for matching patterns, this one looks for matching content.
This check uses backreferences from the groups specified in the source RegEx to construct a string in the target expression to search the target segments. If the target does not contain the correct string it is reported.

For example, look at the following two segments. The QA Checker will find p. 45 in the source segment and will use the 45 as a backreference in the target expression to construct a string which will search the target segment for S. 45. A warning will be reported for the target segment because it contains S. 46, instead of S.45.

RegEx:
  • source - p. (\d)
  • target - S. $1

Source Segment: "See more details on p. 45 of our book."

Target Segment: "Für mehr Details, sehen Sie auf S. 46 unseres Buchs nach."

Another example for this is to check that content written inside square brackets was translated.
RegEx:
  • source - (\[[^]]+\])
  • target - $1
You can also check if a number is present in the target segment, without concern of the order of the numbers being changed in the target. Here, a warning will be reported because 10 is not found in target segment.
RegEx:
  • source - (\b\d+\b)
  • target - \b$1\b

Source Segment: "10 times I told you 100 is enough"

Target Segment: "100 mal habe ich dir gesagt, dass 100 genug ist"

You can use the following example to distinguish between certain character structures. In this example we want a report when "d)" is used for line numbering, but not in any other case.
RegEx:
  • source - (^\w\))
  • target - (^$1)

Source Segment: "d) Pigs and other animals (in Germany)."

Target Segment: "d) Schweine und andere Tiere (in Deutschland)."

This reports "d)" was found in source and target, but if the target would have been "b) Schweine und andere Tiere (in Deutschland).", then there would be no report.
Grouped search expression - report if source and target matches
This uses backreferences from the groups specified in the source RegEx to construct a string in the target expression to search the target segments. If it finds a matching string in the target segment, but with a forbidden variant, it is reported.
Another example might be if sometimes you need to copy a pattern in the source, but change it slightly in the target. If you had currencies written like € 123,45 and they need to be written like 123,45 €, then you can check it like this:
RegEx:
  • source - (€) (\d{3},\d{2})
  • target - $2 $1

For information about backreferences, see Regular expressions.