0

My task is to select every except first letter of each word and convert to lowercase. I've found few similar topics except one simple difference. My characters are Latin Extended and none of those expressions works for me.

Text example:

Kazlų RŪDA, ŽIEŽMARIŲ raj.

And I need such result:

Kazlų Rūda, Žiežmarių raj.

The best i came up:

/\B[\u00C0-\u1FFF\u2C00-\uD7FF\w]/g

Thanks in advance for your help.

Aivaras
  • 3
  • 1
  • Possible duplicate of [Javascript convert unicode string to "Title Case"](http://stackoverflow.com/questions/11933577/javascript-convert-unicode-string-to-title-case) – Laurel May 05 '16 at 20:10

2 Answers2

1

You could do it this way

var str = "Kazlų RŪDA, ŽIEŽMARIŲ raj.";
str = str.replace( /(^\S|\s\S)(\S+)/g , function(m,p1,p2){ return p1+p2.toLowerCase(); } );
// output: "Kazlų Rūda, Žiežmarių raj."
Joseph Marikle
  • 76,418
  • 17
  • 112
  • 129
1

Your regex pattern is good, just use String.replace function with a callback to convert all needed characters to lowercase:

var str = 'Kazlų RŪDA, ŽIEŽMARIŲ raj';
str = str.replace(/[\u00C0-\u1FFF\u2C00-\uD7FF\w]+/g, (m) => m[0] + m.substr(1).toLowerCase());

console.log(str);  // "Kazlų Rūda, Žiežmarių raj"
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105