I need a regex to extract a danish phone number from a string. I got this
var phrase = "Text text text 11 22 33 44 text text.";
phrase = phrase.replace(/^((\(?\+45\)?)?)(\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2})$/, "replace phone number");
alert(phrase);
I found this link, but it does not work:
http://www.dbsoftlab.com/etl-tools/regular-expressions/is-danish-phone-number.html
In the expression you are trying to use, it will only match if the phone number is the only thing in the string, because ^ matches the beginning of the string and $ matches the end.
I believe that this is a much simpler regex that will work:
So, you could say textStr.replace(/([0-9]{2} ){3}[0-9]{2}/g,’new string’).