You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.0 KiB

## RegexReplace
### Instructions
Create a file `RegexReplace.java`.
CON-1881-Review-java-piscine-subjects-Fix-grammar-and-semantic-issues (#2102) * docs(java piscine): Review and update AdventureAbstract exercise * docs(java piscine): Review AdventureCharacter subject * docs(java piscine): Review AdventureInterface subject * docs(java piscine): Review AdventureMonster subject * docs(java piscine): review AdventureSorcerer subject * docs(java piscine): Review AdventureTemplar subject * docs(java piscine): Review AdventureUtils subject * docs(java piscine): Review AdventureWeapon subject * docs(java piscine): Review ComputeArray subject * docs(java piscine): Review FileSearch subject * docs(java piscine): Review FormatDate subject * docs(java piscine): Review KeepTheChange subject * docs(java piscine): Review ListEquals subject * docs(java piscine): Review MapInventory subject * docs(java piscine): Review Observer subject * docs(java piscine): Review Palindrome subject * docs(java piscine): Review RegexReplace subject * docs(java piscine): Review Singleton subject * docs(java piscine): Review StarConstructors subject * docs(java piscine): Review StarGalaxy subject * docs(java piscine): Review StarMass subject * docs(java piscine): Review StarOverride subject * docs(java piscine): Review StarPlanet subject * docs(java piscine): Review StarProperties subject * docs(java piscine): Review StarStatic subject * docs(java piscine): Review StarUtils subject * docs(java piscine): Review StreamCollect subject * docs(java piscine): Review StreamMap subject * docs(java piscine): Review StreamReduce subject * docs(java piscine): Review StringConcat subject * docs(java piscine): Review StringContains subject * docs(java piscine): Review Wedding subject * docs(java piscine): Review WeddingComplex subject * docs(java piscine): Change a part of RegexReplace subject * docs(java piscine): Update AdventureAbstract subject * docs(java piscine): Fix wrong naming parameter -> attribute * docs(java piscine): Remove empty lines * docs(java piscine): Remove ## from line
1 year ago
Write a function `removeUnits` that returns the string where the units `cm` and `€` are removed if they follow directly a number and followed by a space.
Write a function `obfuscateEmail` that returns a string where parts of email addresses are replaced by '*' if they follow the rules below:
- Hide from the username any character next to `-`, `.` or `_` if they exist. Otherwise, hide 3 characters from the username if its length > 3
- If the remaining part after `@` is in the format `@<third level domain>.<second level domain>.<top level domain>`, then hide the third and top level domains, otherwise hide the second level domain and the top level domain if it is not included in `.com`, `.org` and `.net`.
### Expected Functions
```java
public class RegexReplace {
public static String removeUnits(String s) {
// your code here
}
CON-1881-Review-java-piscine-subjects-Fix-grammar-and-semantic-issues (#2102) * docs(java piscine): Review and update AdventureAbstract exercise * docs(java piscine): Review AdventureCharacter subject * docs(java piscine): Review AdventureInterface subject * docs(java piscine): Review AdventureMonster subject * docs(java piscine): review AdventureSorcerer subject * docs(java piscine): Review AdventureTemplar subject * docs(java piscine): Review AdventureUtils subject * docs(java piscine): Review AdventureWeapon subject * docs(java piscine): Review ComputeArray subject * docs(java piscine): Review FileSearch subject * docs(java piscine): Review FormatDate subject * docs(java piscine): Review KeepTheChange subject * docs(java piscine): Review ListEquals subject * docs(java piscine): Review MapInventory subject * docs(java piscine): Review Observer subject * docs(java piscine): Review Palindrome subject * docs(java piscine): Review RegexReplace subject * docs(java piscine): Review Singleton subject * docs(java piscine): Review StarConstructors subject * docs(java piscine): Review StarGalaxy subject * docs(java piscine): Review StarMass subject * docs(java piscine): Review StarOverride subject * docs(java piscine): Review StarPlanet subject * docs(java piscine): Review StarProperties subject * docs(java piscine): Review StarStatic subject * docs(java piscine): Review StarUtils subject * docs(java piscine): Review StreamCollect subject * docs(java piscine): Review StreamMap subject * docs(java piscine): Review StreamReduce subject * docs(java piscine): Review StringConcat subject * docs(java piscine): Review StringContains subject * docs(java piscine): Review Wedding subject * docs(java piscine): Review WeddingComplex subject * docs(java piscine): Change a part of RegexReplace subject * docs(java piscine): Update AdventureAbstract subject * docs(java piscine): Fix wrong naming parameter -> attribute * docs(java piscine): Remove empty lines * docs(java piscine): Remove ## from line
1 year ago
public static String obfuscateEmail(String s) {
// your code here
}
}
```
### Usage
Here is a possible ExerciseRunner.java to test your function
:
```java
import java.io.IOException;
public class ExerciseRunner {
public static void main(String[] args) throws IOException {
System.out.println(RegexReplace.removeUnits("32cm et 50€"));
System.out.println(RegexReplace.removeUnits("32 cm et 50 €"));
System.out.println(RegexReplace.removeUnits("32cms et 50€!"));
CON-1881-Review-java-piscine-subjects-Fix-grammar-and-semantic-issues (#2102) * docs(java piscine): Review and update AdventureAbstract exercise * docs(java piscine): Review AdventureCharacter subject * docs(java piscine): Review AdventureInterface subject * docs(java piscine): Review AdventureMonster subject * docs(java piscine): review AdventureSorcerer subject * docs(java piscine): Review AdventureTemplar subject * docs(java piscine): Review AdventureUtils subject * docs(java piscine): Review AdventureWeapon subject * docs(java piscine): Review ComputeArray subject * docs(java piscine): Review FileSearch subject * docs(java piscine): Review FormatDate subject * docs(java piscine): Review KeepTheChange subject * docs(java piscine): Review ListEquals subject * docs(java piscine): Review MapInventory subject * docs(java piscine): Review Observer subject * docs(java piscine): Review Palindrome subject * docs(java piscine): Review RegexReplace subject * docs(java piscine): Review Singleton subject * docs(java piscine): Review StarConstructors subject * docs(java piscine): Review StarGalaxy subject * docs(java piscine): Review StarMass subject * docs(java piscine): Review StarOverride subject * docs(java piscine): Review StarPlanet subject * docs(java piscine): Review StarProperties subject * docs(java piscine): Review StarStatic subject * docs(java piscine): Review StarUtils subject * docs(java piscine): Review StreamCollect subject * docs(java piscine): Review StreamMap subject * docs(java piscine): Review StreamReduce subject * docs(java piscine): Review StringConcat subject * docs(java piscine): Review StringContains subject * docs(java piscine): Review Wedding subject * docs(java piscine): Review WeddingComplex subject * docs(java piscine): Change a part of RegexReplace subject * docs(java piscine): Update AdventureAbstract subject * docs(java piscine): Fix wrong naming parameter -> attribute * docs(java piscine): Remove empty lines * docs(java piscine): Remove ## from line
1 year ago
System.out.println(RegexReplace.obfuscateEmail("john.doe@example.com"));
System.out.println(RegexReplace.obfuscateEmail("jann@example.co.org"));
System.out.println(RegexReplace.obfuscateEmail("jackob@example.fr"));
}
}
```
and its output :
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
32 et 50
32 cm et 50 €
32cms et 50€!
l lapin jou à la bel ball avec d animau rigolo pour gagner l bill bleu
john.***@*******.com
CON-1881-Review-java-piscine-subjects-Fix-grammar-and-semantic-issues (#2102) * docs(java piscine): Review and update AdventureAbstract exercise * docs(java piscine): Review AdventureCharacter subject * docs(java piscine): Review AdventureInterface subject * docs(java piscine): Review AdventureMonster subject * docs(java piscine): review AdventureSorcerer subject * docs(java piscine): Review AdventureTemplar subject * docs(java piscine): Review AdventureUtils subject * docs(java piscine): Review AdventureWeapon subject * docs(java piscine): Review ComputeArray subject * docs(java piscine): Review FileSearch subject * docs(java piscine): Review FormatDate subject * docs(java piscine): Review KeepTheChange subject * docs(java piscine): Review ListEquals subject * docs(java piscine): Review MapInventory subject * docs(java piscine): Review Observer subject * docs(java piscine): Review Palindrome subject * docs(java piscine): Review RegexReplace subject * docs(java piscine): Review Singleton subject * docs(java piscine): Review StarConstructors subject * docs(java piscine): Review StarGalaxy subject * docs(java piscine): Review StarMass subject * docs(java piscine): Review StarOverride subject * docs(java piscine): Review StarPlanet subject * docs(java piscine): Review StarProperties subject * docs(java piscine): Review StarStatic subject * docs(java piscine): Review StarUtils subject * docs(java piscine): Review StreamCollect subject * docs(java piscine): Review StreamMap subject * docs(java piscine): Review StreamReduce subject * docs(java piscine): Review StringConcat subject * docs(java piscine): Review StringContains subject * docs(java piscine): Review Wedding subject * docs(java piscine): Review WeddingComplex subject * docs(java piscine): Change a part of RegexReplace subject * docs(java piscine): Update AdventureAbstract subject * docs(java piscine): Fix wrong naming parameter -> attribute * docs(java piscine): Remove empty lines * docs(java piscine): Remove ## from line
1 year ago
jan*@*******.co.***
jac***@*******.**
$
```
### Notions
[Pattern](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/regex/Pattern.html)