Python Forum
[Learning:bs4, re.search] - RegEx string cutoff
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Learning:bs4, re.search] - RegEx string cutoff
#1
All I'm trying to do is test print an html string given a regex pattern but the result is always incomplete and I cant figure out why. I'm new to python, and a coding amateur in general... bla bla... But all the regex training sites lead me to believe my pattern will work for this seemingly simple html capture but it keeps getting cut off in the build. I've been trying different flags but I dont think that's the issue. I also know its not the re.py cache. It's gotta be an escape char that I cant figure out, right?

GOAL:
Trying to print: "https://newjersey.craigslist.orgparlin-chevrolet-colorado-call/7014860327.html"
compile result is: "https://newjersey.craigslist.orgparlin-chevrolet-"


from urllib.request import urlopen
from urllib.error import HTTPError
from urllib.error import URLError
from bs4 import BeautifulSoup
import re



str1 = (""" 
bhcgHf4AWry,1:00N0N_iBTHgJR0p0p_2hkovkPhFZk,1:00101_bX2XWbjP0wA,1:00j0j_5naXGGGbBUK,1:00j0j_gbiQHGBLUjL,1:00k0k_fnTDHBeHrt5,1:00s0s_375GQT7ladO" href="https://newjersey.craigslist.orgparlin-chevrolet-colorado-call/7014860327.html">
<span class="result-price">$18000</span>
</a>
""")


print(str1)
reSearch1 = re.search(r'(https:).*(.html)', str1, flags=re.UNICODE)
print(reSearch1)
Output:
bhcgHf4AWry,1:00N0N_iBTHgJR0p0p_2hkovkPhFZk,1:00101_bX2XWbjP0wA,1:00j0j_5naXGGGbBUK,1:00j0j_gbiQHGBLUjL,1:00k0k_fnTDHBeHrt5,1:00s0s_375GQT7ladO" href="https://newjersey.craigslist.orgparlin-chevrolet-colorado-call/7014860327.html"> <span class="result-price">$18000</span> </a> <re.Match object; span=(153, 231), match='https://newjersey.craigslist.orgparlin-chevrolet-> [Finished in 0.2s]
Thanks for any help gents,
Jr
Reply


Messages In This Thread
[Learning:bs4, re.search] - RegEx string cutoff - by jarmerfohn - Nov-09-2019, 06:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  string parsing with re.search() delahug 9 3,787 Jun-04-2020, 07:02 PM
Last Post: delahug
  Regex search for string DBS 3 4,628 Feb-06-2017, 11:39 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020