python - Why this regular expression is not working -
i using python 2.7 scrapy .20
i have test
0552121152, +97143321090
i want value before comma
, value after it.
my regular expression
\s*(.*),
1 before
and ,\s*(.*)
1 after
in both ways got whole test.
why please?
edit
for need full details, here is:
this page scraping http://www.justproperty.com/apartments/old-town/1092713-amazing-2br-apartment-in-the-old-town-island-with-a-burj-khalifa-and-address-hotel-view.html
and scrapy code in cmd in shell:
s =sel.xpath("normalize-space(.//span[@class='content_agent']/span[last()]/span[2]/text())") s.re(r'\s*(.*),')
note
i not asking solution these values, asking why mentioned-regular expression not working
try doing way:
import re string = "0552121152, +97143321090" pattern = re.compile(r"\s*(.*),\s*(.*)") print pattern.search(string).groups()
result:
('0552121152', '+97143321090') [finished in 0.3s]
the difference might because used .groups()
method, that's why i'm getting it. if can reproduce on end, it's not regular expression wrong coding style.
other that, fail see how regex fails @ all.
Comments
Post a Comment