Reputation: 163
In the document I'm translating there's a large number of dates of the type 12.05.2011
. I need to replace the month numbers (in the middle) with month names, like -May-
, which would give 12-May-2011
. This is necessary because some readers might wrongly assume that the month number is in the beginning and not the middle.
For some reason, the regexp I came up with, ^(?<=[\d]{2})\.05\.(?=[\d]{2,4})$
, only works if I remove the ^
and the $
symbols that bookend it. Why is that?
In the image below, the regexp fails to select .05.
unless I remove those ^
and $
.
P.S. I want to search for strings that fill the whole translation segment, because there might by chance be some non-date string, say, some production code, 2135.05.2011.462
, and my search-and-replace might wrongly put -May-
in there. ^_^ That would wreck my translation.
Until I manage to use the ^...$
there, I will use this as a crude way to make sure that at least the day number is within the 01-39 range: (?<=[0-3][0-9])\.05\.(?=20{0,1}[\d]{2})
. This also makes sure that the year number, if it has 4 digits, has 20
as the first two of them (because in my documents the dates are usually from the 21st century).
Upvotes: 0
Views: 332
Reputation: 17
Don't use RegEx for this, but use the built-in options. They're well hidden, but they work quite well. SDL will automatically adapt the date format without any manual effort.
If you want to change the options for projects you create in the future: File menu > Options > Language Pairs > [relevant language pair] > Translation Memory and Automated Translation > Auto-substitution > Dates and Times.
If you want to apply the changes to an existing project: Project Settings > Language Pairs > [relevant language pair] > Translation Memory and Automated Translation > Auto-substitution > Dates and Times.
Choose a long date and a short date. I think you want d-MMM-yy as the long date, or perhaps dd.MMM.yyyy as the short date. Just test some of them to see which give the best results.
Upvotes: 1
Reputation: 7157
^ means starting a line, $ means ending a line. That you don't mean searching for the whole string in a line right?
The following regex works with your case:
(?<=[\D\.][\d]{2})\.\d{2}\.(?=[\d]{2,4})
Upvotes: 0
Reputation: 163
It looks like in Trados, you should put the ^
and the $
inside the lookbefore and lookbehind brackets, like this:
(?<=^[0-3][0-9])\.05\.(?=[\d]{2,4}$)
If this answer of mine gets downvoted, I'll know I was wrong, but it seems to work thus far.
Upvotes: 0