2

I tried slugify and slug packages but strings like കവാടം പൊളിക്കണം: "ലോ അക്കാദമിക്കു" നോട്ടിസ് return a blank string instead of കവാടം-പൊളിക്കണം-ലോ-അക്കാദമിക്കു-നോട്ടിസ്. Words should be preserved, special characters should be stripped.

Is there a way to generate slugs that preserves arbitrary non-English words?


Regular expression to match non-English characters? seems the best resource for matching international words.

Community
  • 1
  • 1
Jesvin Jose
  • 22,498
  • 32
  • 109
  • 202

2 Answers2

1

This following regEx match-replace worked fine for spaces only.

var s    = 'കവാടം പൊളിക്കണം: "ലോ അക്കാദമിക്കു" നോട്ടിസ്';
var res  = s.replace(/ /g,"-");
console.log( res );

For all special characters you can use following.

var s    = 'കവാടം പൊളിക്കണം: "ലോ അക്കാദമിക്കു" നോട്ടിസ്';

// Keep symbols you want to replace with hyphen.
var res  = s.replace(/[&\/\\#,+()$~%.'":*?<>{} ]/g,"-");
console.log( res );
Jimish Fotariya
  • 1,004
  • 8
  • 21
0

This should be simple enough to do with String.prototype.replace() or with regular expressions. Did you try:

'കവാടം പൊളിക്കണം'.replace(' ', '-')

It returns "കവാടം-പൊളിക്കണം".

Martin
  • 15,820
  • 4
  • 47
  • 56