Python Forum
steps to debug regular expressions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
steps to debug regular expressions
#1
i am trying to make more use of module re. this time i am scanning all the files in (a copy of) /var/log to rename the files after log rotation. but my regular expression is not matching anything. it should match a select few files. is there a common methodology to debug regular expressions?

i'm not showing what i have done so no one is temped to do it for me.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
there are numerous online testers that you can use, for example: https://regex101.com/
google 'debug regular expressions online' for more
Reply
#3
Using the re.VERBOSE flag also helps write expressions on several lines with comments.
Reply
#4
the re.VERBOSE flag isn't helping any. it lets me write weirder expressions. at least re.DEBUG helped a little.

what seemed to be happening was that it was applying my compiled pattern to the whole string, not just a portion (as seen in things like the egrep command). so i filled out the expression with ^.* and .*$ to make it applicable to the whole string. that made it work.

the re.DEBUG flag was interesting. i made a little command to compile expressions with that flag. it let me see what they get compiled into (presumably in the form of some coding).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  this message show up for me. cant debug notinhg here davidthomas 0 650 Jun-29-2023, 05:44 PM
Last Post: davidthomas
  How in Eclipse recognize debug / run mode? AlekseyPython 1 2,236 Mar-21-2019, 08:26 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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