fork download
  1. import re
  2. html = """1.45;" >1234 St1 St</p> <p class=3D"highlight-address" styl=\ne=3D"margin: 0; font-family: 'Montserrat', sans-serif; text-decoration: non=\ne; color: #323232; font-weight: 500; font-size: 13px; line-height: 1.45;" =\n>City, ST 12345</p><p class=3D"highlight-specs" style=3D"margin: 0; fo=\nnt-family: 'Montserrat', sans-serif; text-decoration: none; color: #323232;=\n font-weight: 500; font-size: 13px; line-height: 1.45;"><span style=3D"disp=\nlay: inline-block;">4 bd</span><span style=3D"display: inline-block;">&nbsp=\n;=E2=80=A2&nbsp;</span><span style=3D"display: inline-block;">2 ba</span><s=\npan style=3D"display: inline-block;">&nbsp;=E2=80=A2&nbsp;</span><span styl=\ne=3D"display: inline-block;">1,596 sqft</span></p><p class=3D"highlight-spe=\ncs" style=3D"margin: 0; font-family: 'Montserrat', sans-serif; textdecorati=\n\n1.45;" >5678 St2 Rd</p> <p class=3D"highlight-address" sty=\nle=3D"margin: 0; font-family: 'Montserrat', sans-serif; text-decoration: no=\nne; color: #323232; font-weight: 500; font-size: 13px; line-height: 1.45;" =\n >City2, ST 6789</p><p class=3D"highlight-specs" style=3D"margin: 0=\n; font-family: 'Montserrat', sans-serif; text-decoration: none; color: #323=\n232; font-weight: 500; font-size: 13px; line-height: 1.45;"><span style=3D"=\ndisplay: inline-block;">4 bd</span><span style=3D"display: inline-block;">&=\nnbsp;=E2=80=A2&nbsp;</span><span style=3D"display: inline-block;">4 ba</spa=\nn></p><p class=3D"highlight-specs" style=3D"margin: 0; font-family: 'Montse=\nrrat', sans-serif; textdecoration: none; color: #323232; font-weight: 500; =\n\n1.45;" >91011 St3 Rd</p> <p class=3D"highlight-address" style=\n=3D"margin: 0; font-family: 'Montserrat', sans-serif; text-decoration: none=\n; color: #323232; font-weight: 500; font-size: 13px; line-height: 1.45;" >=\nCity2, ST 10111</p><p class=3D"highlight-specs" style=3D"margi=\nn: 0; font-family: 'Montserrat', sans-serif; text-decoration: none; color: =\n#323232; font-weight: 500; font-size: 13px; line-height: 1.45;"><span style=\n=3D"display: inline-block;">4 bd</span><span style=3D"display: inline-block=\n;">&nbsp;=E2=80=A2&nbsp;</span><span style=3D"display: inline-block;">2 ba<=\n/span><span style=3D"display: inline-block;">&nbsp;=E2=80=A2&nbsp;</span><s=\npan style=3D"display: inline-block;">2,376 sqft</span></p><p class=3D"highl=\night-specs" style=3D"margin: 0; font-family: 'Montserrat', sans-serif; text="""
  3. pattern = r"\b(\d+)\s*ba<(?:\S*(?:\s(?!ba<|sqft<)\S*)*>(\d[,.\d]*)\s*sqft\b)?"
  4. matches = re.findall(pattern, html)
  5. for ba,sqft in matches:
  6. if not sqft:
  7. sqft = "0"
  8. print(f"{ba}, {sqft}")
Success #stdin #stdout 0.02s 9444KB
stdin
Standard input is empty
stdout
2, 1,596
4, 0
2, 2,376