-2

I'd like to capture the regular expression of two numbers between a slash within a string (basically a date: dd/mm). I have this so far:

\d{2}\/\d{2}

This seems to capture most of what I want, however it also captures

2002/06

Which has four numbers on the left hand side. I only want it to match if it has two numbers either side of the slash. How do I do this?

clattenburg cake
  • 1,096
  • 3
  • 19
  • 40
  • 1
    Specify the start of the line using `^`, use a positive lookbehind to check for whitespace before the numbers, or use a negative lookbehind to make sure the match does not have any numbers directly before it. – Jesse Jul 28 '22 at 23:28

1 Answers1

0

Add word boundaries around it.

\b\d{2}\/\d{2}\b
Barmar
  • 741,623
  • 53
  • 500
  • 612