user3568044 user3568044 - 10 days ago 6
Python Question

Regular expression for matching letters followed by digits

I have to match the citations within a document. The citations can be of the forms:
Author names, year; Author names(year); (Author names,year)
For example: 'James et al., 2010', 'James & Juda, 2010', 'James & Juda(2010)','(James & Juda, 2010)'.
I have tried:

[A-Za-z]+[0-9]{4}


and

(([A-Z]([A-Za-z][&.,])+\d{4})


One or more occurrences of characters followed by some punctuations and then 4 digits( specifying year) is what I meant. But its not working. Please help me with this regard.

Answer

Below regular expression will match all the samples which you have given.

(\S+\s*)+?(,|\()\s*(\d+)\)?

Comments