1

I'm working on a class that will take the title of an article and post in the URL field. The class itself copies the field and removes characters such as '@' or '/' and replaces it with '-'.

Everything has worked well for languages using the Latin alphabet, however using other alphabets, e.g. Cyrillic, has caused this error upon saving: "Invalid URL name. The URL name can include only unicode characters and hyphens, and it can't begin or end with a hyphen.: URL Name".

The removal of the characters is controlled by String.removeAll(regExp,'-') with "regExp" being defined as [: / . , \\[ \\] ( ) « » & % > < ’’ | ¿ – - \' ´ · + ” " ’ : „ ť “ — —].

I have also tried the encodeUrl(,UTF-8) method which once again worked perfectly for the Latin alphabet, but the Cyrillic alphabet was returned in an alphanumeric mix.

Can anybody help with the implementation of the Cyrillic alphabet? Any help or ideas would be greatly appreciated.

Here is my current attempt:

final String regExp = '[: / . , \[ \] ( ) « » & % > < '' | ¿ – - \' ´ · + " " ’ : „ ť " —]'; 
String title = 'Онлайн-развлечения — Заказ';
String urlName = title.replaceAll(regExp,'-'); 
urlName = urlName.replace('----','-'); 
urlName = urlName.replace('---','-'); 
urlName = urlName.replace('--','-'); 
urlName = urlName.replace('ť','t');
2
  • 1
    Can you share the actual code you have and, ideally, some of the things you tried and failed at? Sep 3, 2020 at 15:30
  • Hi Sebastian, I added the code to my original question
    – jdrees
    Sep 4, 2020 at 7:25

0

You must log in to answer this question.

Browse other questions tagged .