Skip to content
Advertisement

Tag: regex-group

Capture substring and send it to a function that modifies it and can replace it in this string

Incorrect output that I am getting, because if I incorrectly capture the substrings, the replacements will also be incorrect Having well-defined limits, I don’t understand why this capture pattern try to capture beyond them? And the output that I need is that: Answer There are several errors in your code, among which: You are printing the result of the one_day_or_another_day_relative_to_a_date_func

Merge the matches from regular expressions into a single list

I am trying to separate a string in CamelCase into a single list I managed to separate the words with regular expressions But I am clueless on how create a single list of all the matches I tried to concatenate the lists, append something like that but I don’t think it would work in my case output: Desired output: Answer

Python RegEx check string

im trying to set correct version on output. I have this possible strings: 0.0.4.1 # 1. 7.51.4.1 # 2. 0.1.4.1 # 3. and i need to check, if the “0.” is on the start (to set output without 0. or 0.0.) Output 1. will have just “4.1”, 2. gonna stay the same and 3. will be 1.4.1 Im trying to

groupdict in regex

I have the following string: I wrote a regex for this which will find the first-name and last-name of user: Result: Sometimes, I don’t get the last name. At that time, my regex fails. Can any one have any idea regarding this? Answer You may use See the regex demo Regex details ^ – start of string (?:(?:M(?:(?:is|r)?s|r)|[JS]r).?s+)? – an

Match non-capturing group multiple times

I tried really hard to make a good title, but I’m not sure if I’m asking this right. Here’s my best attempt: I’m using Python’s flavor of regex I need to match numbers using named groups: but should not match: my best attempt so far has been: I’m using [sa-z] instead of a word-boundary because 15×20 are two different values.

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