Skip to content

Tag: regex

Using regular expression for a field name in a Django

I have a model in Django that has the fields photo_1, photo_2, photo_3 and many other fields that does not contains the “photo” string on their names. Also, the photo fields can be blank, so I can find some rows with empty photo fields. For the html template, is there a way to go through the field…

escaping square brackets from string in dataframe

I have a dataframe where i am try to clean the data from all cols. There are some annomalies in teh data like this: “[n], [ta], [cb]” basically anything in square brackets i want to ignore and replace with a space. I have this: this works except I still get the square brackets in the data but they…

Python Regex pL matching issues

I’m trying to match a list of keywords I have, taking care to include all Latin characters (e.g accented). Here’s an example gives: Which looks correct. However: gives: This is wrong, as I expect a match for “u blah”. I’ve tried to also use Pythons built in re module, but I canno…

Find bit sequences that do not include specific sequence

I’m trying to find all non-overlap bit sequences satisfied the following constraints: starts with 0 ends with 110 or 111 does not contain 000 Here is my non-regex code in python: My current regex pattern is (0(^(?!000))*(?:110|111)). It doesn’t accept any bit between starting 0 and ending bits. Fo…

Regex to keep one choice in square bracket

I am trying to write a regex to replace the whole square bracket with the first choice. For example, [ choice A | choice B ] I want to replace the previous square bracket as a whole with choice A. However, when I have more than one of these brackets: [ choice A | choice B ] and choose between