LeoD
LeoD

Reputation: 2072

Regex to capture dates that appear after certain keywords

I have a series of text files that I need to process, with content like this:

Bla bla data base: 07/08/2014 Data para pagamento do rendimento: 14/08/2014 Valor distribuído por cota: R$ 0,83.

I need to capture the dates in the files, but I also need to qualify the dates that I find. For example, after the keyword "base", if there is a date, I'd like to capture it (the first date found after the word "base"). Between the word "base" and the date there can be a number of other words or characters.

The dates can be in format d/M/yyyy or dd/MM/yyyy.

I'm trying the following Regex pattern:

"base.+(?<date>[0123]?[0-9]/[01]?[0-9]/[12]?[90]?[0-9][0-9])"

But I'm not getting the correct results.

Could anyone help me?

Thanks

Upvotes: 1

Views: 57

Answers (1)

luoluo
luoluo

Reputation: 5533

Try the no greedy version.

base.+?([0123]?[0-9]/[01]?[0-9]/[12]?[90]?[0-9][0-9])

Upvotes: 2

Related Questions