mercredi 6 juillet 2016

Write a python regular expression for matching dot and array indices

I need to match the proper variable access strings ex.

employeeobj.empid
employeeobj.grades[0].grade
employee[0]
employee.dept.location.room[0]

Few examples -

employeeobj.[] Invalid
.employeeobj Invalid
[]employeeobj Invalid
employeeobj.dept. Invalid

employeeobj.dept valid
employeeobj.dept[9] valid
employeeobj[1].dept valid

A proper access string of a variable and or object in an object oriented like Java. I need the regex to be in python

More specifically, I need to match all the strings which

  • does not start with a dot, opening or closing square bracket
  • does not end with a dot, and opening square bracket
  • has no dots side by side
  • has proper square brackets with proper integer index
  • a square bracket always followed by a dot, only exception if it is at the end, then there is no need for a dot

Thanks

Aucun commentaire:

Enregistrer un commentaire