Python Forum
Thread Rating:
  • 2 Vote(s) - 1.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
regular expression question
#1
hey there, im a newbie who just started learning python, and i had a problem here:

import re
a = re.compile(r'(\d\d\d-){1,2}?\d\d\d\d')
print(a.findall('111-222-1112, 111-333-2222, 155-2333'))
so as u guys can probably see, i want the code to be able to identify both \d\d\d-\d\d\d\d and \d\d\d-\d\d\d-\d\d\d\d , but something went wrong, and the program ends up returning ['222-', '333-', '155-']
i cant really find y its wrong. ik how to write it so that it does what its supposed to do but im just curious of the mistake ive made that i cannot find.
Reply


Messages In This Thread
regular expression question - by Sanlus - Aug-04-2018, 04:43 PM
RE: regular expression question - by buran - Aug-04-2018, 04:47 PM
RE: regular expression question - by Sanlus - Aug-04-2018, 04:52 PM
RE: regular expression question - by micseydel - Aug-04-2018, 04:50 PM
RE: regular expression question - by micseydel - Aug-04-2018, 05:05 PM
RE: regular expression question - by buran - Aug-04-2018, 06:12 PM
RE: regular expression question - by volcano63 - Aug-04-2018, 06:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Regular expression help anilrajr 4 504 May-08-2024, 06:18 PM
Last Post: deanhystad
  data validation with specific regular expression shaheen07 0 402 Jan-12-2024, 07:56 AM
Last Post: shaheen07
  Regular Expression search to comment lines of code Gman2233 5 1,789 Sep-08-2022, 06:57 AM
Last Post: ndc85430
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 1,784 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
  Need help with my code (regular expression) shailc 5 2,054 Apr-04-2022, 07:34 PM
Last Post: shailc
  Regular Expression for matching words xinyulon 1 2,236 Mar-09-2022, 10:34 PM
Last Post: snippsat
  regular expression question Skaperen 4 2,604 Aug-23-2021, 06:01 PM
Last Post: Skaperen
  How can I find all combinations with a regular expression? AlekseyPython 0 1,735 Jun-23-2021, 04:48 PM
Last Post: AlekseyPython
  Python Regular expression, small sample works but not on file Acernz 5 3,078 Jun-09-2021, 08:27 PM
Last Post: bowlofred
  Regular expression: cannot find 1st number in a string Pavel_47 2 2,488 Jan-15-2021, 04:39 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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