Skip to content
Advertisement

Tag: regex

competing regular expressions (race condition)

I’m trying to use python PLY (lex/yacc) to parse a language called ‘GRBL’. GRBL looks something like this: The ‘G’ Codes tell a machine to ‘go’ (or move) and the coordinates say where. LEX requires us to specify a unique regular expression for every possible ‘token’. So in this case I need a regex that will clearly define ‘G00’ and

Regex Pattern in Python for special charaters

I asked a similar question a few days ago on here and it was great help! A new challenge I wanted build is to further develop the regex pattern to look for specific formats in this iteration, and I thought I have solved it using regex 101 to build/test a regex code but when applied in Python received ‘pattern contain

Python regex that matches superscripted text

My question is very simple but I couldn’t figure it out by myself: how to I match superscripted text with regex in Python? I’d like to match patterns like [a-zA-Z0-9,[]] but only if it’s superscripted. regards Answer The main problem is that information about “superscript” and “subscript” text is not conveyed at the character level. Unicode even defines some characters

Replace character in file name with regex python

My script should replace the “|” character of a file it finds via regex in a directory with an “l”. The code runs but filenames are not replaced. What is wrong? Answer Joshua’s answer and the many comments, especially the suggestions from ekhumoro, already pointed out issues and guided to the solution. Fixed and improved Here is my copy-paste ready

Regular expression matching of the contents of text files in a directory

I have a directory of text files. I need to set a status for each file based on whether it matches 1, both or neither regex patterns. My plan is: Walk directory If the file’s content: does not match either pattern, status = 1 matches pattern1 BUT NOT pattern2, status = 2 matches pattern2 BUT NOT pattern1, ignore matches pattern1

Advertisement