var substitute_with = "_";
const regex = /\B\w/g;
var result = text.replaceAll(regex, substitute_with);
This code substitutes all letters with underscore, except the first one in all words.
This works fine for the English language, but I need the same with both English and Cyrillic.
Example:
Это текст-"рыба", часто используемый в печати и вэб-дизайне.
Online regex: https://regex101.com/r/scjHae/1
Could you help me?
>Solution :
You could use Unicode property escapes (with u flag), and instead of \B, use a look behind assertion:
const result = "They all shouted Слава Україні!".replaceAll(/(?<=\p{L})\p{L}/gu, "_");
console.log(result);