I would like to extract full name from the string using regular expression. How can i do that? This code gives me empty value of result. What's wrong?
var p = '№ 46/20 John Smith Newmore 23.01.2020';
var result = p.match(/^([a-zA-Z0-9]+|[a-zA-Z0-9]+\s{1}[a-zA-Z0-9]{1,}|[a-zA-Z0-9]+\s{1}[a-zA-Z0-9]{3,}\s{1}[a-zA-Z0-9]{1,})$/);
My expected result matches the regular expression:
Existing data - string: '№ 46/20 John Smith Newmore 23.01.2020'
Expected result: 'John Smith Newmore'
p.replace(/[^a-zA-Z ]+/g,'').trim()p.replace(/[^а-яА-ЯёЁa-zA-Z ]+/g,'').trim()if you ask for Russian ones. Orp.replace(/[^\u0400-\u04FFa-zA-Z ]+/g,'').trim()to handle any Cyrillic chars.p.replace(/[^\u0400-\u04FFa-zA-Z ]+/g,'').trim()will work with all Cyrillic chars.