How could I modify the transform function, so that
transform("3 Feb 1987") returns "1987 02 3"
?
I know that I could achieve it by adding extra java code,
so that it gets the month string, and then transform it into a number using a simple hashmap, for instance.
However, I would like to achieve this without adding any extra java code, just by modifying only the Pattern.compile and matcher.replaceAll instructions.
Would this be possible with your transducer?
I am thinking something such as the following:
Pattern pattern = Pattern.compile("(\d+) (Jan=01|Feb=02|Mar=03) (\d\d\d\d)");
Matcher matcher = pattern.matcher(input);
return matcher.replaceAll("$3 $2 $1");
Do you know how to achieve this?
-----
ps: This is just an example for me to understand; I know that I could achieve it by using the Date formating and parsing functions of Java (so, without using regular expressions)
Tags:
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I would like to know if I could use the transducer in your package to solve this issue:
Currently, I have the following function using regular expressions:
String transform(String input) {
Pattern pattern = Pattern.compile("(\d+) (Jan|Feb|Mar) (\d\d\d\d)");
Matcher matcher = pattern.matcher(input);
return matcher.replaceAll("$3 $2 $1");
}
transform("3 Feb 1987") returns "1987 Feb 3"
That's ok.
How could I modify the transform function, so that
transform("3 Feb 1987") returns "1987 02 3"
?
I know that I could achieve it by adding extra java code,
so that it gets the month string, and then transform it into a number using a simple hashmap, for instance.
However, I would like to achieve this without adding any extra java code, just by modifying only the Pattern.compile and matcher.replaceAll instructions.
Would this be possible with your transducer?
I am thinking something such as the following:
Pattern pattern = Pattern.compile("(\d+) (Jan=01|Feb=02|Mar=03) (\d\d\d\d)");
Matcher matcher = pattern.matcher(input);
return matcher.replaceAll("$3 $2 $1");
Do you know how to achieve this?
-----
ps: This is just an example for me to understand; I know that I could achieve it by using the Date formating and parsing functions of Java (so, without using regular expressions)
Tags: