Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

My Python Regex Expression is not working properly in my code

I have this regex expression that work on regex101.
But in my python code, it is returning None.
If you guys can help me out that would be great.

Link to my regex expression
https://regex101.com/r/T0Jvq4/1

This is my function.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

legalDescription = tryRegexData(r"(?<=Legal Description:)(\n)(.*)^(?:(?!Property Use:).)*",propertyArea,0)

def tryRegexData(regex,area,num):

  try: 
      return re.search(regex,area.text).group(num).strip()
  except Exception as e:
      return ""

Thank you

>Solution :

I would suggest simplifying your pattern and just use dot all mode:

def tryRegexData(area):

  try: 
      return re.search(r'\bLegal Description:\s+(.*?)\s+Property Use:', area.text, flags=re.S).group(1)
  except Exception as e:
      return ""
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading