HI @arthur_bazin​ ,
Â
if you want to convert a date from dd/mm/yyyy to yyyy-mm-dd there is a simpler solution: the DateTimeConverter, setting output format to %Y-%m-%d (ISO date).
Â
Hope that helps!
HI @arthur_bazin​ ,
Â
if you want to convert a date from dd/mm/yyyy to yyyy-mm-dd there is a simpler solution: the DateTimeConverter, setting output format to %Y-%m-%d (ISO date).
Â
Hope that helps!
Hi @davtorgh​ ,Â
​Â
Thanks for your answer, I know this transformer, it can be very helpful but it is very limited, your data need to be really "clean" (if I can say that) to use it.
​
My case is very complex, I need to extract date from very different patterns. ​
With regex I've identified more than 30 different patterns that could be easily converted to date. And I'm searching more complexe ones.
Some of them :
2020//01/01
2020/1/01
2020 Jan 01 @ 12h00​
...
​Regular expression are very useful to detect all these case without any error. ​
​
But my problem is that for every searching pattern, I need to write the extracting pattern (don't know the name, maybe replacement pattern? The pattern that has to be return .
With named groups, I could write only one extract pattern for all searching pattern.
​
But thanks for your answer !
Have a nice day! ​
When I've had to deal with converting dates that come in a variety of formats I've used the following approach.
Conditionally setting an attribute that holds the input format based on regex matches. Then using this attribute in a Date Time Converter
Â
Which gives the following
Â
Not sure if this is more or less work than the approach you are trying to take, I've fortunately only had to deal with 4 or 5 patterns
Hi @davtorgh​ ,Â
​Â
Thanks for your answer, I know this transformer, it can be very helpful but it is very limited, your data need to be really "clean" (if I can say that) to use it.
​
My case is very complex, I need to extract date from very different patterns. ​
With regex I've identified more than 30 different patterns that could be easily converted to date. And I'm searching more complexe ones.
Some of them :
2020//01/01
2020/1/01
2020 Jan 01 @ 12h00​
...
​Regular expression are very useful to detect all these case without any error. ​
​
But my problem is that for every searching pattern, I need to write the extracting pattern (don't know the name, maybe replacement pattern? The pattern that has to be return .
With named groups, I could write only one extract pattern for all searching pattern.
​
But thanks for your answer !
Have a nice day! ​
HI @arthur_bazin​ ,
Â
I've been doing some testing myself and seems FME accept named groups inside search pattern but not inside the substitution pattern.
Â
Bye
Hi @davtorgh​ ,Â
​Â
Thanks for your answer, I know this transformer, it can be very helpful but it is very limited, your data need to be really "clean" (if I can say that) to use it.
​
My case is very complex, I need to extract date from very different patterns. ​
With regex I've identified more than 30 different patterns that could be easily converted to date. And I'm searching more complexe ones.
Some of them :
2020//01/01
2020/1/01
2020 Jan 01 @ 12h00​
...
​Regular expression are very useful to detect all these case without any error. ​
​
But my problem is that for every searching pattern, I need to write the extracting pattern (don't know the name, maybe replacement pattern? The pattern that has to be return .
With named groups, I could write only one extract pattern for all searching pattern.
​
But thanks for your answer !
Have a nice day! ​
Ah ! What a nice surprise :-)
Â
I will try in more different way with other transformers and functions.
Thank's a lot @davtorgh​ for looking at this !!
Â
Best regards.
When I've had to deal with converting dates that come in a variety of formats I've used the following approach.
Conditionally setting an attribute that holds the input format based on regex matches. Then using this attribute in a Date Time Converter
Â
Which gives the following
Â
Not sure if this is more or less work than the approach you are trying to take, I've fortunately only had to deal with 4 or 5 patterns
Hi @ebygomm​ !
Â
Thanks for your answer.
Actually, this is more or less what I'm doing : I'm using an attribute creator in which I extract data into a new field.
Â
Like you, I'm using conditionnal values but like this :
(I'm using lot's of parameters to easily control what I'm searching for)
If the data contains a pattern, I extract the date accordingly.
The resulting date have this pattern YYYY-MM-DD which is exactly the pattern used by date format (so I don't have to use a date formater).
Â
Here the extract function for the first line (in french) :
@ReplaceRegEx(@Value(__ct_DFA_attribute_processed),".*(t0-2]b0-9]-0-9]-0-9])(?:années|année|ans|an|\\/|-){0,2}()0-1]}0-9])(?:mois|m|\\/|-){0,2}()0-3]}0-9])(?:jours|jour|j|\\/|-){0,2}(?:- | |a|à ){0,2}(a0-2]{0-9])(?:heures|heure|h|\\/|-|:){0,2}(|0-6]{0-9])(?:minutes|minute|min|m|\\/|-|:){0,2}(|0-6]{0-9])(?:secondes|seconde|sec|s|\\/|-|:){0,2}.*",\\1-\\2-\\3)
What I whant to do is having this form :
@ReplaceRegEx(@Value(__ct_DFA_attribute_processed),".*(?<year>e0-2]t0-9]>0-9]]0-9])(?:années|année|ans|an|\\/|-){0,2}(?<month>m0-1]&0-9])(?:mois|m|\\/|-){0,2}(?<day>t0-3]&0-9])(?:jours|jour|j|\\/|-){0,2}(?:- | |a|à ){0,2}(|0-2]Ã0-9])(?:heures|heure|h|\\/|-|:){0,2}(\0-6]|0-9])(?:minutes|minute|min|m|\\/|-|:){0,2}(\0-6]|0-9])(?:secondes|seconde|sec|s|\\/|-|:){0,2}.*",\\<year>-\\<month>-\\<day>)
Â
It could help me to improuve my workbench and simplify it.
Â
Have a nice day.
Â
Ok,
Â
So I've made a lot's of tests and I can confirmed, named groups are just ignored.
Â
If you have this data : "01/01/2020"
With this pattern : "(?<day>t0-3]30-9])\\/(?<month>t0-1]10-9])\\/(?<year>t0-2]20-9]90-9]90-9])"
Â
You can only extract data by using the number of order : "\\3-\\2-\\1" to extract this : "2020-01-01"
If you try to use one of these forms, it will only display these character, there is no substitutions : \\g{year} or \\g<year> or \\g'year' or \\k{year} or \\k<year> or \\k'year' or "$+{year}" or $3 or $+3 or \\g3
Â
I feel disappointed because these patterns come from the official PERL documentation which is the one recommanded by Safe to look at for REGEX.
If someone @safesoftware safesoftware​ could implement this, it would be a real advantage.
Â
Best regards
Â
Ok,
Â
So I've made a lot's of tests and I can confirmed, named groups are just ignored.
Â
If you have this data : "01/01/2020"
With this pattern : "(?<day>t0-3]30-9])\\/(?<month>t0-1]10-9])\\/(?<year>t0-2]20-9]90-9]90-9])"
Â
You can only extract data by using the number of order : "\\3-\\2-\\1" to extract this : "2020-01-01"
If you try to use one of these forms, it will only display these character, there is no substitutions : \\g{year} or \\g<year> or \\g'year' or \\k{year} or \\k<year> or \\k'year' or "$+{year}" or $3 or $+3 or \\g3
Â
I feel disappointed because these patterns come from the official PERL documentation which is the one recommanded by Safe to look at for REGEX.
If someone @safesoftware safesoftware​ could implement this, it would be a real advantage.
Â
Best regards
Â
Suggest it as an idea here
https://community.safe.com/s/idea/Idea
I have been testing the RegEx for 2 days now and I confirm that RegEx can be used both in search and in replacement, at least with my two versions FME2014 and FME2017. I think your problem is due to your pattern. I tested the text:
12/31/2022
with the search pattern:
^([0-3][0-9])\\/([0-1][0-9])\\/([0- 2][0-9][0-9][0-9])$
and the replacement pattern:
\\3-\\2-\\1
and it works properly in StringReplacer with result:
2022-12-31
Here, a good place for RegEx testing:
https://rubular.com/
Â
FME2014 result:
Â
FME2017 result:
I have been testing the RegEx for 2 days now and I confirm that RegEx can be used both in search and in replacement, at least with my two versions FME2014 and FME2017. I think your problem is due to your pattern. I tested the text:
12/31/2022
with the search pattern:
^([0-3][0-9])\\/([0-1][0-9])\\/([0- 2][0-9][0-9][0-9])$
and the replacement pattern:
\\3-\\2-\\1
and it works properly in StringReplacer with result:
2022-12-31
Here, a good place for RegEx testing:
https://rubular.com/
Â
FME2014 result:
Â
FME2017 result:
Hi @jeff_beaudry​ !
Thanks for your answer, this is exactly what I'm doing.
But in my case, I'm changing the REGEX depending on what need to be tested ; for example :
- 01/01/2020 => (g0-9][0-9])\\/()0-9][0-9])\\/()0-9][0-9][0-9][0-9]) => $3-$2-$1
- 2020-01-01=> (g0-9][0-9][0-9][0-9])-(90-9][0-9])-(90-9][0-9]) => $1-$2-$3
So depending on what my field containt, I change the REGEX I use.
But it forces me to change the substitution pattern.
Â
Using named groups can allows me to keep the same substitution pattern.
- 01/01/2020 => (?<day>a0-9];0-9])\\/(?<month>t0-9];0-9])\\/(?<year>a0-9];0-9]]0-9]]0-9]) => ${year}-${month}-${day}
- 2020-01-01=> (?<year>a0-9];0-9]]0-9]]0-9])-(?<month>t0-9];0-9])-(?<day>a0-9];0-9]) => ${year}-${month}-${day}
Â
Hi @jeff_beaudry​ !
Thanks for your answer, this is exactly what I'm doing.
But in my case, I'm changing the REGEX depending on what need to be tested ; for example :
- 01/01/2020 => (;0-9]-0-9])\\/(\0-9]-0-9])\\/(\0-9]-0-9]-0-9]-0-9]) => $3-$2-$1
- 2020-01-01=> (;0-9]-0-9]-0-9]-0-9])-()0-9]-0-9])-()0-9]-0-9]) => $1-$2-$3
So depending on what my field containt, I change the REGEX I use.
But it forces me to change the substitution pattern.
Â
Using named groups can allows me to keep the same substitution pattern.
- 01/01/2020 => (?<day>&0-9]00-9])\\/(?<month>&0-9]00-9])\\/(?<year>&0-9]00-9]00-9]00-9]) => ${year}-${month}-${day}
- 2020-01-01=> (?<year>&0-9]00-9]00-9]00-9])-(?<month>&0-9]00-9])-(?<day>&0-9]00-9]) => ${year}-${month}-${day}
Â
Sorry @arthur_bazin​, I misread. I hadn't noticed that you were talking about a named group. I just tested myself and it doesn't work in FME 2017:
Â
Replacement pattern tried unsuccessfully:
\\g3-\\g2-\\g1
\\g{3}-\\g{2}-\\g{1}
\\year-\\month-\\day
\\gyear-\\gmonth-\\gday
\\g{year}-\\g{month}-\\g{day}
$+{year}-$+{month}-$+{day}
%+{year}-%+{month}-%+{day}
$-{year}-$-{month}-$-{day}
year-month-day
Â
It's a bit late, but I voted for your idea :-)
Hi @jeff_beaudry​ !
Thanks for your answer, this is exactly what I'm doing.
But in my case, I'm changing the REGEX depending on what need to be tested ; for example :
- 01/01/2020 => (;0-9]-0-9])\\/(\0-9]-0-9])\\/(\0-9]-0-9]-0-9]-0-9]) => $3-$2-$1
- 2020-01-01=> (;0-9]-0-9]-0-9]-0-9])-()0-9]-0-9])-()0-9]-0-9]) => $1-$2-$3
So depending on what my field containt, I change the REGEX I use.
But it forces me to change the substitution pattern.
Â
Using named groups can allows me to keep the same substitution pattern.
- 01/01/2020 => (?<day>&0-9]00-9])\\/(?<month>&0-9]00-9])\\/(?<year>&0-9]00-9]00-9]00-9]) => ${year}-${month}-${day}
- 2020-01-01=> (?<year>&0-9]00-9]00-9]00-9])-(?<month>&0-9]00-9])-(?<day>&0-9]00-9]) => ${year}-${month}-${day}
Â
No problem
Thanks for your vote, I hope they could add this feature !!