0

I am scratching my head over this. For example I have:

Date
sometext
somtext
27-7-2013

What I want to do is I want to get the first date format string pattern after the Date keyword. Here is what I currently have:

(?i)(?<=date.*)\d+-\d+\d+

But unfortunately, I am getting nothing and if I just try to get all the string after the date keyword, e.g.

(?i)date.*

I am only getting the result as:

Date[CR]

I am using Expresso to test out my regular expressions. I am pretty new with using regex so I am not familiar with how to do things and stuff.

Please help! Thanks!

user488792
  • 1,943
  • 7
  • 31
  • 38
  • You need to enable single-line matching. Try adding a `(?s)` flag in front. – Rohit Jain Jun 27 '13 at 08:56
  • 1
    Not sure if expresso supports non-fixed length lookbehinds. I know that very few engines supports it. Also, try to use `(?s)`, this should match newlines with `.`. Which means try the following: `(?s)(?i)date.*?\d+-\d+-\d+` – HamZa Jun 27 '13 at 08:56

2 Answers2

0

I would not use a lookbehind assertion in this case, also unlimited length lookbehinds are (I think) only supported by .net.

I would use a capturing group instead:

(?is)date.*?(\d{1,2}-\d{1,2}-\d{4})

You will find the date in the first capturing group.

See it here on Regexr

(?is) is enabling the case independent matching mode i and the single line mode s, that makes the . also match newline characters.

.*? is matching lazily any characters.

(\d{1,2}-\d{1,2}-\d{4}) matches one or two digits, a dash, one or two digits, a dash, then 4 digits.

stema
  • 90,351
  • 20
  • 107
  • 135
0

You can have a look at this regex:

(?i)(?<=Date)[\S\s]*?(\d{1,2}-\d{1,2}-(?:\d{4}|\d{2}))

In your regex you are also missing a - before last \d+. Also this regex will handle the year part with four digits as well as two digits.

NeverHopeless
  • 11,077
  • 4
  • 35
  • 56