python - Regex to match MediaWiki template without certain named parameter -


i’ll point: need regex matches template out of list that have date parameter - assuming (singleton now) list of templates “stub”, things below in bold should matched:

  • {{stub}}
  • {{stub|param}}
  • {{stub|date=a}}
  • {{stub|param|date=a}}
  • {{stub|date=a|param}}
  • {{stub|param|date=a|param}} note: “param” means any number of parameters there.

additionally, nice if match if date parameter blank, not required.

the current regex have far is

{{((?:stub|inaccurate)(?!(?:\|.*?\|)*?\|date=.*?(?:\|.*?)*?)(?:\|.*?)*?)}} 

however matches fourth , sixth items in list above.

note: (?:stub|inaccurate) make sure template either stub or inaccurate template.

note 2: flavor of regex here python 2.7 module re.

i think it's enough have negative look-ahead, tries match date @ position?

{{((?:stub|inaccurate)(?!.*\|date=).*)}}

if empty date parameters have | following equals sign, use

{{((?:stub|inaccurate)(?!.*\|date=[^|}]).*)}}


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -