Slini Elf Slini Elf - 1 year ago 85
Javascript Question

regex search date in string

I want to search for a date at a string with javascript (e.g.;) and show the date when I found it. I found a really nice regex ( but it doesn't work to my string: "27.11." or "27.11.2016" works, but "abcde 27.11.2016 fghi" doesn't work (result: "-1"). The regex can't find the date because of these charaters in front and behind the date :/. I googled for 2 hours but didn't found an anwser (how to change the regex the right way?). I also looked at the basis regex-expressions but I coundn't find an answer :/.

Does someone know how to filter the date out of the string?

Thank you :-).

Answer Source

You could try the same code, but replace $ and ^ with regex word boundry \b. The code should look like this:


The code above will match:



But it will not match:



and it will match any date that has a string before/after it:

abcde 27.11.2016


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download