Skip to content
Advertisement

Tag: regex

Dashes with(out) spaces with python’s regex

What I’ve managed to do I’m new to both python and regex. With python’s re.compile, in massive number of text files, I wanted to find all kinds of dashes surrounded by spaces. I used: (Yeah, I know about the regex module on PyPI, but I’m trying to use what I know better) It seems to have worked fine: I got

Python regular expression how to deal with multiple back slash

I’m dealing with text data and having problem erasing multiple back slashes. I found out that using .sub works quite well. So I coded as below to erase back slash+r n t f v However, the code above can’t deal with the string below. So coded as this: But it’s showing result like this.. I don’t know why this happens.

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

Put comma after a pattern in python regex

Just like the question says I am trying to add a comma at the end of a pattern or sub string. I found 3 solutions that should do the job, and look logical too. But they are not changing anything. I will show you all those codes. The goal is to find out if there is something that I am

Regex expression for words with length of even number

I want to write a regex expression for words with even-numbered length. For example, the output I want from the list containing the words: {“blue”, “ah”, “sky”, “wow”, “neat”} is {“blue”, “ah”, “neat}. I know that the expression w{2} or w{4} would produce 2-worded or 4-worded words, but what I want is something that could work for all even numbers.

Disable metacharacters in regular expressions

Perl has Q and E operators in its regular expression toolkit: Does such a facility exist in Python? I am aware of the in operator to do literal string comparison, but my usecase is that I’m using the lineinfile Ansible module which relies on Python’s regular expression library. I’d like something like this (if you can see the intent even

Advertisement