Advertisement
Guest User

Untitled

a guest
Sep 15th, 2011
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. def which_date(text):
  2.     usemdy = re.findall("<ref>[^<]+\|\s*date\s*=[^|]+\d+,?\s*\\d{4}", text)
  3.     useymd = re.findall("<ref>[^<]+\|\s*date\s*=\s*\d{4}-\d{2}-\d{2}", text)
  4.     usedmy = re.findall("<ref>[^<]+\|\s*date\s*=\s*\d+[^|]+\d{4}", text)
  5.     if useymd >= usemdy and useymd >= usedmy: return 'useymd'
  6.     if usemdy >= usedmy: return 'usemdy'
  7.     return 'usedmy'
  8.  
  9. t1 = 'Wikipedia text here<ref>{{cite web|title=test|date=Sept. 5, 2006}}</ref>'
  10. t2 = 'Text here<ref>{{cite web | date= 2006-04-01 | title=test}}</ref>'
  11. t3 = "Text here<ref>{{cite web | date = 5 September, 2005}}</ref>"
  12. >>> which_date(t1)
  13. 'usemdy'
  14. >>> which_date(t2)
  15. 'useymd'
  16. >>> which_date(t3)
  17. 'usedmy'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement