Can anyone help me converting this code in java?
$linkc= strtolower(preg_replace(array('/[^a-zA-Z0-9-éèàê€-]/', '/(-){2,9}/'), '_', $jour['nom']));
$linkc = preg_replace('/€/', '_', $linkc);
$link .= preg_replace('/[èéêëàáâãåäæìíîïòóôõöøùúûü]/', '', $linkc);
$nom = $jour['nom'];
I'm really new to regular expression,first of all, I don't really understand array('/[^a-zA-Z0-9-éèàê€-]/', '/(-){2,9}/')
what this pattern means, then , I tried myself with
String nom = rubrique.getNom();
nom = nom.replaceAll("[èéêëàáâãåäæìíîïòóôõöøùúûü]", "");
nom = nom.replaceAll("[^a-zA-Z0-9-éèàê€-]", "_");
nom = nom.replaceAll("(-){2,9}", "_");
which doesn't remove the accent letters....
Thanks for any help!!!
The expression
array('/[^a-zA-Z0-9-éèàê€-]/', '/(-){2,9}/')
means:
"one of the regex in the array must fit". These regex are:
'/[^a-zA-Z0-9-éèàê€-]/'
- just one character which is not a-z and not A-Z and not 0-9 and not é etc. Probably not what you want?
'/(-){2,9}/'
- just at least 2 up to max 9 "-" - probably also not what you want.
In order to substitue all accent chars by "-":
... '/[éèàê€]+/', '-' ....
Have a look at this as well, you might test regex against input "on the fly"
Furthermore: preg_replace
might have arbitrary results on multibyte chars. You probably have a look at mb_ereg_replace which is capable to handle multibyte chars like é in the expression etc.