I am getting some content into a website and need to process the entry titles so that they don’t contain any dates. More specifically, a string such as “Lorem ipsum 30-08-2011 dolor” needs to become “Lorem ipsum dolor”. I have to take into account dates such as: 30-08-2011, 30.08.2011 and 30/08/2011.
After searching around I tried something like this, but it doesn’t work:
str.replace(/^(0?[1-9]|[12][0-9]|3[01])[\/\-\.](0?[1-9]|1[012])[\/\-\.]\d{4}$/, '');
Any help is greatly appreciated. Thanks!
Remove the
^and$if you want to match the pattern inside a string. Your current regex will only match a string that only contains a date.Also, if you want to remove multiple dates from a string, you need to use a global regex, by adding a
gafter the closing/.