Relative Content

Tag Archive for pythonregex

How to use python regex to get the first occurrence of a substring [duplicate]

This question already has answers here: Regular expression to stop at first match (10 answers) Splitting on first occurrence (5 answers) Closed last month. I have the following script trying to get the first occurrence of the word “symbol”, but it keeps returning the last one (print “symbol in the middle and end”). How can […]

in python using re.sub how do i interpolate text [duplicate]

This question already has answers here: Adding characters after a certain word in Python using regex (3 answers) Closed last month. I want to scan for the situation where a certain string ‘INC0459444’ is next to a date as in the following example INC04594442024-06-05 If this is the case, I want to interpolate the text […]

Find expression if other expression is in string

expression1 = r’d+ed+e’ #e.g ’10e2e’ or ’30e4e’ expression2 = r’d+%/d+%’ #e.g ‘30%/1%’ or ‘1%/2% For a given string, I want to extract expression1 only if expression2 is present in the string. Example: string1 = ’30e4e 1%/2%’ -> re.search(correctRegex, string1, re.X).group(0) #should return ’30e4e’ string2 = ’30e4e blabla’ -> re.search(correctRegex, string2, re.X) #should be None string3 […]

python3.12.3 print warning when use d to match numbers [duplicate]

This question already has answers here: What exactly is a “raw string regex” and how can you use it? (7 answers) DeprecationWarning: invalid escape sequence – what to use instead of d? [duplicate] (2 answers) Closed 6 days ago. I upgrade python to 3.12.3, below code report a warning: SyntaxWarning: invalid escape sequence ‘d’ Does […]

python3.12.3 print warning when use d to match numbers [duplicate]

This question already has answers here: What exactly is a “raw string regex” and how can you use it? (7 answers) DeprecationWarning: invalid escape sequence – what to use instead of d? [duplicate] (2 answers) Closed 6 days ago. I upgrade python to 3.12.3, below code report a warning: SyntaxWarning: invalid escape sequence ‘d’ Does […]

python3.12.3 print warning when use d to match numbers [duplicate]

This question already has answers here: What exactly is a “raw string regex” and how can you use it? (7 answers) DeprecationWarning: invalid escape sequence – what to use instead of d? [duplicate] (2 answers) Closed 6 days ago. I upgrade python to 3.12.3, below code report a warning: SyntaxWarning: invalid escape sequence ‘d’ Does […]