Skip to content
Advertisement

Tag: regex

Python find all occurrences of hyphenated word and replace at position

I have to replace all occurrences of patterns with hyphen like c-c-c-c-come or oh-oh-oh-oh, etc. with the last token i.e. come or oh in this example, where The number of character between hyphen is arbitrary, it can be one ore more characters the token to match is the last token in the hyphenation, hence come in c-c-come. the input string

ERROR: Bucket name must match the regex “^[a-zA-Z0-9.-_]{1,255}$”

When I try to upload images to a bucket, it throw an error “Invalid bucket name “thum.images “: Bucket name must match the regex “^[a-zA-Z0-9.-_]{1,255}$””. I think there is nothing wrong with a bucket name. This is my code to upload image: Answer The “Invalid bucket name “thum.images “: Bucket name must match the regex “^[a-zA-Z0-9.-_]{1,255}$”” error means just what

Efficient regex with lists

I have a list of strings coming from os.listdir() that looks like the following: out of those entries, I wanna get the ones that match the “backup_YYYYMMDD” pattern. The regex for that, with named groups, would be I am trying to create a list that contains the date only from the above (aka the .group(‘date’)), but I cannot find a

Python Web Scraping Div

I’m trying to scrape the job list from a web site, but I do not have enough experience with scraping. I found that all jobs are in a div block like this : What I want to access is the job title, job description and job link (<a href=”..”). Unfortunately, I couldn’t understand the logic for accessing them. So far

Find first word in string Python

I have to write a single function that should return the first word in the following strings: All have to return the first word and as you can see some start with a whitespace, have apostrophes or end with commas. I’ve used the following options: Both error at some of the strings, so who can help me??? Answer It is

Validate card numbers using regex python

I have some credit card numbers with me and want to validate them over the below rules. ► It must only consist of digits (0-9) ► It may have digits in groups of 4, separated by one hyphen “-” ► It must NOT have 4 or more consecutive repeated digits ► It may contain exactly digits without any spaces Input:

python regex: duplicate names in named groups

Is there a way to use same name in regex named group in python? e.g.(?P<n>foo)|(?P<n>bar). Use case: I am trying to capture type and id with this regex: /(?=videos)((?P<type>videos)/(?P<id>d+))|(?P<type>w+)/?(?P<v>v)?/?(?P<id>d+)? from this strings: /channel/v/123 /ch/v/41500082 /channel /videos/41500082 For now I am getting error: redefinition of group name ‘id’ as group 6; was group 3 Answer The answer is: Python re does

Advertisement