2,091 questions
Score of -3
-3
votes
2 answers
2
answers
76 views
76
views
How to use a list in a pattern in re.match
I'm making a program to automate a task, and at some point in it I need to use a list comprehension [f for f in ...] to make a list, and I want to use re.match() or re.search() to compare the files in ...
Advice
3
votes
11
replies
278
views
Integer Partition Regex
I need to construct a regex given an integer n that matches any partition of n with a leading +. For example, if n=10, it should match +10, +9+1, +1+9, +1+8+1 etc.
Since there are only finitely many ...
Score of 2
2
votes
4 answers
4
answers
613 views
613
views
regex for matching a pattern with an optional part
I need a regex pattern to find substrings of the form "a:<some integer>" and an optional "b:<some float>" in a large string. The "a" string may be preceded ...
Score of 3
3
votes
3 answers
3
answers
143 views
143
views
Python regular expression for text search
I am trying to extract wanted text from a given set of text. I have created below function.
def extract_name(title):
matches = re.findall(r'\b[A-Z0-9\s&.,()-]+(?:\s*\(\d\))?\b', title)
...
Score of 0
0
votes
1 answer
1
answer
120 views
120
views
Predicting `re` regexp memory consumption
I have a large (gigabyte) file where an S-expression appears, and I want to skip to the end of the S-expression. The depth of the S-expression is limited to 2, so I tried using a Python regexp (b'\\((?...
Score of 4
4
votes
2 answers
2
answers
206 views
206
views
Using re.sub and replace with overall match [duplicate]
I was just writing a program where I wanted to insert a newline after a specific pattern. The idea was to match the pattern and replace with the overall match (i.e. capture group \0) and \n.
s = "...
Score of 0
0
votes
1 answer
1
answer
79 views
79
views
Match characters between square brackets but only if text inside brackets follows pattern [duplicate]
I want to match text inside of square brackets - but ONLY if it contains hashtag+digit+digit
i.e [#18] or [hello #25 bye]
NOT [25] (no hashtag)
I ultimately want to remove these match strings (...
Score of 1
1
vote
2 answers
2
answers
81 views
81
views
Counting the hashtags in a collection of tweets: two methods with inconsistent results
I'm playing around with a numpy dataframe containing two columns: 'tweet_text' and 'cyberbullying_type'. It was created through this dataset as follows:
df = pd.read_csv('data/cyberbullying_tweets.csv'...
Score of 1
1
vote
1 answer
1
answer
257 views
257
views
Static typing of Python regular expression: 'incompatible type "str"; expected "AnyStr | Pattern[AnyStr]" '
Just to be clear, this question has nothing to do with the regular expression itself and my code is perfectly running even though it is not passing mypy strict verification.
Let's start from the basic,...
Score of 0
0
votes
1 answer
1
answer
46 views
46
views
re.findall with requests doesn't match copied and pasted html (generated by requests.text)
I'm trying to capture some elements from the html code of a certain url.
When I copy and paste the contents of the html directly to into my python code it works well.
import re
# Sample HTML content
...
Score of -1
-1
votes
1 answer
1
answer
61 views
61
views
How to create a regex with an optional group without merging it with another group? [duplicate]
I'm trying to write a regex pattern in Python to capture two groups, where the second group is optional, but I want the groups to remain distinct.
Here is are examples of the possible pattern I want ...
Score of 1
1
vote
2 answers
2
answers
106 views
106
views
re.sub eats next charater when replacing with more [duplicate]
so i was trying to format my text for markdown v2, basically I just want to replace a special character a with \a
when trying to do this with regex, it does so< but the new symbol eats up the next ...
Score of -3
-3
votes
2 answers
2
answers
88 views
88
views
Extracting string from ann email body
I'm using python to extract the information provided from the body of an email using imap.
Part of the email that interests to my code:
"BOT ID: 4824CF8B-2986-11EC-80F0-84A93851B964"
I can ...
Score of 0
0
votes
1 answer
1
answer
64 views
64
views
Regex get parse inet value
I want to parse ifconfig to get ip_address, net mask and broadcast. and these are optional fields. If it present, it should return but if not it should return None.
My below pattern works fine but if '...
Score of 1
1
vote
1 answer
1
answer
67 views
67
views
Issue with Toggling Sign of the Last Entered Number in Calculator Using ⁺∕₋ in Python
I am developing a calculator using Python. The problem I'm facing is that when I try to toggle the sign of the last number entered by the user using the ⁺∕₋ button, all similar numbers in the text get ...