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
Tag: regex
how to check if a string fullfil with multiple regex and capture that portion that match?
What I want I’m working with a django form and it takes a password input. I need to pass the input value for multiple regexes, which will test if: at least one character is a lowecase at least one character is a uppercase at least one character is a number at least one character is a especial character (symbol) 8
Can this beautifulsoup script be simplified with Regex?
I wrote some beautifulsoup scripts, and one part seems really redundant, I am thinking if it can be simplified with Regex. All posts from this forum are marked with different colors, what I did is to search each color with one line. For six colors I did six lines with only one words difference. I am not sure if it
Regex Python – Keep only ASCII and copyright symbol
I have the following function to keep only ASCII characters: But now I also want to keep the copyright symbol (©). What should I add to the pattern? Answer Add the copyright symbol’s hex xA9 (source) to your match group: Regex101
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