2013-06-08

Various Regular Expressions

Community > Replace value with a null
The point of this question is how to replace a character string like 'Today' or 'Day N' (N is a digit) with a null value so that only valid datetime strings formatted in "YYYY-mm-dd HH:MM:SS" will be preserved.
Of course, using the StringSearcher or the StringReplacer with a regular expression would be a solution. But there should be various approaches, which is more preferable?
Since there could be several patterns for non-datetime strings in such a case, we might need to prepare several regular expressions (and transformers) when filtering them out perfectly. However, for the datetime strings, we need only one expression. Even if new non-datetime string pattern appears in the future, we don't need to touch the expression.
So, I thought considering about a regular expression for the datetime strings is better rather than for non-datetime strings.

Addition:
The StringReplacer with the following settings can replace non-datetime string with a blank and also format a datetime string into 14 digits (YYYYmmddHHMMSS) simultaneously.
Text to Find: ^(([0-9]{4})-([0-9]{2})-([0-9]{2})\s([0-9]{2}):([0-9]{2}):([0-9]{2}))?(.*)$
Replacement Text: \2\3\4\5\6\7
Use Regular Expressions: yes

No comments:

Post a Comment