M
M
MaximDoshi2015-06-10 15:59:34
PHP
MaximDoshi, 2015-06-10 15:59:34

Regular expressions, only letters, how to set for German or French or Italian or Ukrainian?

Regular expressions, only letters, how to set for German or French or Italian or Ukrainian? Only letters are needed. For example, for English - [A-Za-z], but what will it be for other languages, who knows, please tell me?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Ineshin, 2015-06-10
@IonDen

Well, as it were: jsfiddle.net/IonDen/k0xhg4c8

var a = "Привет, чувак! 111111";
var b = a.replace(/[^А-Яа-я]/gi, '');
console.log(b); // -> Приветчувак

R
Ruslan Saiko, 2015-06-10
@RuslanSaiko

string text = "Hello, world. Привет мир 123 456 789 [email protected]#t$.%^&*()`☻";
            Console.WriteLine("Входная строка: {0}", text);
            Regex rex = new Regex(@"\p{L}",  RegexOptions.Multiline);
            var matches = rex.Matches(text);
            StringBuilder textResult = new StringBuilder();
            foreach (Match item in matches)
            {
                textResult.Append(item.Value);
            }
            Console.WriteLine("Результат: {0}", textResult.ToString());
            Console.ReadLine();

or
string text = "Hello, world. Привет мир 123 456 789 [email protected]#t$.%^&*()`☻";
            Console.WriteLine("Входная строка: {0}", text);
            Regex regex = new Regex(@"[^\p{L}]", RegexOptions.Multiline);
            var textResult = regex.Replace(text, string.Empty);
            Console.WriteLine("Результат: {0}", textResult);

Conclusion:
Входная строка: Hello, world. Привет мир 123 456 789 [email protected]#t$.%^&*()`☻
Результат: HelloworldПриветмирdfqt

Works for all unicode characters

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question