Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError Regex
#5
(Jun-22-2019, 02:22 PM)snippsat Wrote: Your string start with one white-space and end with two,when using ^ and $ it most match the begin/end of string exactly on each line.
Could be written like this numRegex = re.compile(r"^\s\d{1,3}(,(\d{3})).*$")
Or if strip of white-space it will also work.
import re

numRegex=re.compile(r"^\d{1,3}(,(\d{3}))*$")
mo = numRegex.search(" 12,124,123,221  ".strip())
print(mo.group())

oh, yeah, i don't know it before. tks verymuch. So it doesn't seem very convenient
Reply


Messages In This Thread
AttributeError Regex - by linh_py - Jun-22-2019, 12:51 PM
RE: AttributeError Regex - by ThomasL - Jun-22-2019, 01:26 PM
RE: AttributeError Regex - by linh_py - Jun-22-2019, 01:33 PM
RE: AttributeError Regex - by snippsat - Jun-22-2019, 02:22 PM
RE: AttributeError Regex - by linh_py - Jun-22-2019, 03:33 PM
RE: AttributeError Regex - by DeaD_EyE - Jun-23-2019, 09:01 PM

Forum Jump:

User Panel Messages

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