Skip to main content

Hi,

I'm using @ReplaceRegEx and I've tryed to use named capturing group but I think that it isn't possible, could you confirm that ?

 

Here some information about capturing group : https://www.regular-expressions.info/named.html

 

With REGEX, you can use () to capture a group.

@ReplaceRegEx allows you to call this group into the result of this function by using the number of order of the group.

Here the function that allow me to transform '01/01/2020' to '2020-01-01' :

@ReplaceRegEx('01/01/2020', ( 0-2]20-9]90-9]90-9])\\/(/0-1]10-9])\\/(/0-3]30-9]),

",\\3-\\2-\\1)

 

But with REGEX you can name these groups like that (?<name>group) so our function will be like this :

@ReplaceRegEx('01/01/2020', (?<year>g0-2]-0-9]-0-9]-0-9])\\/(?<month>g0-1]-0-9])\\/(?<day>g0-3]-0-9]),

",\\<year>-\\<month>-\\<day>)

 

I've tryed different form to call these groups : <name>, ${name}, $+{name}, \\g{name} but none of them works.

 

So, is there any possibility to use REGEX group ? If not, is it something you could imagine to add ?

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

 

regex

Which gives the followingresult

 

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

 

regex

Which gives the followingresult

 

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 :

1

(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


Suggest it as an idea here

https://community.safe.com/s/idea/Idea

Done, thank's.

 

https://community.safe.com/s/idea/0874Q000000j0EtQAI/detail


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:

image 

FME2017 result:

image


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:

image 

FME2017 result:

image

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 !!


Reply