-1

I have the following RegEx syntax that will match the first date found.

([0-9]+)/([0-9]+)/([0-9]+)

However, I would like to start from the end of the content and search backwards. In other words, in the below example, my syntax will always match the first date, but I want it to match the last instead.

Some Text here
01/02/15
Some additional
text here.
10/04/14
Ending text
here

I believe this is possible by using a negative lookahead, but all my attempts failed at this because I don't understand RegEx enough. Help would be appreciated.

Note: my application uses RegEx PCRP.

JadonR
  • 143
  • 2
  • 8
  • The rule is like this: `pattern(?!.*pattern)`. If `.` does not match line break chars, [make it](https://stackoverflow.com/questions/159118). – Wiktor Stribiżew Dec 30 '19 at 23:57

1 Answers1

1

You could make the dot match a newline using for example an inline modifier (?s) and match until the end of the string.

Then make use of backtracking until the last occurrence of the date like pattern and precede the first digit with a word boundary.

Use \K to forget what was matched and match the date like pattern.

^(?s).*\b\K[0-9]+/[0-9]+/[0-9]+

Regex demo

Note that the pattern is a very broad match and does not validate a date itself.

The fourth bird
  • 96,715
  • 14
  • 35
  • 52
  • For some reason, both of those match everything up to the last date. I only want it to match on the last date. If you look here at my original regex, it only matches on the date. https://regex101.com/r/9kvECV/1 – JadonR Dec 30 '19 at 23:38
  • @JadonR I have updated the pattern to match the date only. – The fourth bird Dec 30 '19 at 23:40