Skip to content

Tag: regex

Returning empty string for missing capture group Python regex

I’m working on parsing string text containing information on university, year, degree field, and whether or not a person graduated. Here are two examples: What I am struggling to accomplish is to have an entry for each school experience regardless of whether specific information is missing. In particular, imagine I wanted to pull whether each degree was finished from ex1

Simple regex on string

I’m working on a simple mention system and in my PHP script and I need to extract client:6 from the larger text where one or more @mention like @[John Doe (#6)](client:6) will be present. Ex. This is my text how do you like it @John and do you have any thoughts @Jane In php the string will look like. and

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

How to make a regular expression for this seemingly simple case?

Is it possible to write a regular expression that works with String replaceAll() to remove zero or more spaces from the end of a line and replace them with a single period (.). For example, a regex that will make these (non-exhaustive) test cases pass: I know I can do it with replaceFirst(” *$”, “.”), but I’m wondering if it