Skip to main content
Filter by
Sorted by
Tagged with
2 votes
4 answers
330 views

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 ...
user1479670's user avatar
  • 1,355
3 votes
3 answers
132 views

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) ...
Totura's user avatar
  • 167
0 votes
1 answer
103 views

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'\\((?...
Erik Carstensen's user avatar
4 votes
2 answers
189 views

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 = "...
DuesserBaest's user avatar
  • 3,215
0 votes
1 answer
45 views

I would like to match a regular expression in a string and add the character 0 after all occurrences. That is, each match will be replaced with itself followed by 0. But because 0 is a digit, I don'...
Ed Avis's user avatar
  • 1,622
0 votes
1 answer
71 views

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 (...
lolo's user avatar
  • 79
1 vote
2 answers
55 views

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'...
Sam's user avatar
  • 494
1 vote
1 answer
184 views

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,...
toto's user avatar
  • 367
0 votes
1 answer
44 views

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 ...
Addoodi's user avatar
  • 13
-1 votes
1 answer
49 views

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 ...
user1142252's user avatar
1 vote
2 answers
78 views

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 ...
George's user avatar
  • 27
-3 votes
2 answers
82 views

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 ...
HC DARK BOT's user avatar
0 votes
1 answer
63 views

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 '...
premganesh's user avatar
1 vote
1 answer
57 views

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 ...
Araz_devp's user avatar
-1 votes
2 answers
77 views

I am trying to get my head around regular expressions and was playing with some examples trying to see what it comes out at. I am struggling to understand how the order of element in OR (|) impacts ...
Martin S.'s user avatar
8 votes
2 answers
228 views

I'm working with a set of regex patterns that I have to match in a target text. My problematic regex is something like this: (İg)[[:punct:][:space:]]+[[:alnum:]]+ Initially, I noticed that Python’s re ...
Paolo Magnani's user avatar
1 vote
1 answer
135 views

I have a irregular format pdf invoice files with multiple pages. I want excel file in return with data extracted from pdf files. For this I write code with plumberpdf library in python but I am able ...
Hannan Wali's user avatar
0 votes
0 answers
33 views

I have a text file (latin-1-encoded) with this content: 1 lorem ipsum 1 ... 1 OCTOBER 24, 2024 11/27/13 lorem ipsum 2 ... 1 ...
ostpoller's user avatar
  • 119
0 votes
0 answers
57 views

I need a function to sanitize regex patterns in Python, specifically targeting strings that may contain wildcard characters (%). The goal is to replace these % wildcards with the regex equivalent .* ...
Abinash Biswal's user avatar
2 votes
1 answer
106 views

I'm trying to use re.findall(pattern, string) to match all numbers and however many duplicates follow in a string. Eg. "1222344" matches "1", "222", "3", "...
Ethan's user avatar
  • 41
-1 votes
2 answers
186 views

I am extracting data from an API call and am using this code: if response.status_code == 200: ReportResponse = re.search('<return>(.+?)</return>', response.text) print(...
Steve's user avatar
  • 19
0 votes
1 answer
80 views

It is necessary to write a regular expression to search for natural numbers in the text. Numbers can be inside words and any special characters. The main condition for the search is a sequence of ...
CollonelDain's user avatar
0 votes
1 answer
49 views

I have the following string str = '2024-09-23 18:05:08,147 INFO [WatchDog_191084] (alloc:0MB, cpu:0%) 10 422' and I am trying to extract the numbers between the squared brackets. so I am ...
Eliseo Di Folco's user avatar
2 votes
1 answer
49 views

import requests, re r = requests.get('example.com') p = re.compile('\d') print(p.match(str(r.text))) This always prints None, even though r.text definitely contains numbers, but print(p.match('...
Red Dwarf's user avatar
  • 728
1 vote
1 answer
77 views

I'm working on auto replacing contents in a file, the re.search() are successfully got the new_content, but it contains special characters and when I want to use re.sub() it shows : error: invalid ...
Gabriel Za's user avatar
0 votes
2 answers
85 views

Consider the following example >>> import sys, re >>> sys.version '3.11.5 (main, Sep 11 2023, 13:23:44) [GCC 11.2.0]' >>> re.__version__ '2.2.1' >>> re.findall('a{1,...
rasul's user avatar
  • 1,129
1 vote
1 answer
92 views

I want to convert complex file output into a simpler version, but I can't seem to get the regex right. I have tried using regex and pandas to convert this weird formatted code to something nicer but ...
Pad's user avatar
  • 911
-1 votes
1 answer
74 views

The code is supposed to split the string without removing the delimiters. import re operations = '8-8/84' operations = re.split(r'([+,*,/,-])', operations) Executing the code, operations ends up with ...
eye egg's user avatar
  • 21
-3 votes
1 answer
75 views

I've been trying to translate these two for loops into list comprehension: with open(sourceFile, 'r+t') as file: for line in file: for key, value in patterns.items(): ...
ludovico's user avatar
0 votes
1 answer
87 views

In Python common regex functions, re.match, re.search, re.fullmatch, etc. return a match object and to print the result we have to use match.group(): re.search(pattern, string): Searches for the first ...
NBS's user avatar
  • 49
0 votes
0 answers
39 views

I have this string "~/goofy.git$ /home/maria/L1-07-51.mdl /home/maria/L1-08-09.res" I want to find every occurrence of a string that starts /home and ends in either res or mdl. And: I want ...
Mikke Mus's user avatar
  • 155
-1 votes
2 answers
86 views

I want to extract all possible substrings which have all the vowels from a string. For example in the code: import re text = "thisisabeautifulsequencofwords" pattern = r"(?=.*a)(?=.*e)(?...
Arjo's user avatar
  • 25
1 vote
1 answer
95 views

I've written a python script that uses strftime() from the time module. On my windows 10 computer I get the long form format for time zone when I call strftime("%Z"), and I want to ...
HeKaiNani's user avatar
-1 votes
1 answer
40 views

I am trying to match either a higher-case letter followed by a lower-case letter or just a higher-case letter. Many questions were answered about how to get higher-case or lower-case letters, but I ...
Jabed A. Mohammed's user avatar
0 votes
0 answers
54 views

I have a file with nested brackets. I need to parse the text within the top-level brackets with Python regex. import re string = '{a {b} c} {d}' # desired output: ['a {b} c', 'd'] # non-greedy ...
zest16's user avatar
  • 679
1 vote
1 answer
55 views

So I have this excerpt of the .msg file below. What I wish to do is for all the [sel xxx xxx] headers find them then read the lines below them. If any of the answers contain a (+3) or any (+x) then ...
Medusa's user avatar
  • 21
-2 votes
3 answers
73 views

What I want to do is validate user inputs. The criterion is only numeric inputs are allowed, no alpha, no characters like .,/?<> etc. Say a user inputs 1989, it will print true But if the user ...
cutelittlebunny's user avatar
1 vote
1 answer
72 views

I have some strings look like: *.rem.1.gz and *.rem.2.gz And I want to replace it into *.1.trim.gz and *.2.trim.gz The number 1 and number two files are paired with each other, which I want to create ...
Pluto Liu's user avatar
5 votes
0 answers
124 views

Here is re.compile: >>> import re, inspect >>> print(inspect.getsource(re.compile)) def compile(pattern, flags=0): "Compile a regular expression pattern, returning a Pattern ...
wim's user avatar
  • 368k
0 votes
1 answer
44 views

The documentation seems clear but it begs the question, what is the purpose of re.match? Couldn't re.search with the caret (^) be used instead as long as the MULTILINE flag is not enabled? Is re.match ...
Kevin Eldurson's user avatar
1 vote
2 answers
166 views

I'd like to find all occurrences of a substring while ignoring some characters. How can I do it in Python? Example: long_string = 'this is a t`es"t. Does the test work?' small_string = "test&...
Franck Dernoncourt's user avatar
1 vote
1 answer
91 views

I need to extract the volume with regular expression from strings like "Candy BAR 350G" (volume = 350G), "Gin Barrister 0.9ml" (volume = 0.9ml), "BAXTER DRY Gin 40% 0.5 ml&...
Veronica Isakova's user avatar
2 votes
1 answer
72 views

I am making a modulatory function that will take keywords with special characters (@&\*%) and keep them intact while all other punctuation is deleted from a sentence. I have devised a solution, ...
linkey apiacess's user avatar
2 votes
1 answer
71 views

I want to match all cases where a hyphenated string (which could be made up of one or multiple hyphenated segments) ends in a consonant that is not the letter m. In other words, it needs to match ...
Paige Cox's user avatar
-3 votes
1 answer
24 views

I want to replace part of a string based on re.sub method as below import re re.sub("([0-9]_F)$", '[0-9]_DO', 'sdsd3_F') However I fail to manage the numerical part of match which is also a ...
Bogaso's user avatar
  • 3,896
0 votes
1 answer
69 views

I have a complicated string that includes a kilometer range and a fee for users that fall into that range. Ideally, I would like to transform the string into something that I could use to easily ...
Feiznia's user avatar
  • 15
-2 votes
1 answer
40 views

There is a string "123:987 767687:99 145:986 156:876 " My regex expression is (\d{3}):\1 I expecting the result is 123:987, 145:986, 156:876 there is no result found. i dont undertsand. ...
Анатолій's user avatar
0 votes
1 answer
54 views

I try to catch values entered in syntax like this one name="Game Title" authors="John Doe" studios="Studio A,Studio B" licence=ABC123 url=https://example.com command=&...
fauve's user avatar
  • 321
4 votes
1 answer
155 views

import re x = re.compile(r"hello") In the above code, x is determined to have type re.Pattern[str]. But why is re.Pattern generic, and then specialized to string? What does a re.Pattern[...
bzm3r's user avatar
  • 4,664
0 votes
1 answer
107 views

I am trying to write a python script which would redact/hide certain data present in a string before logging it out to the console. Below is my code snippet so far. import re from logging import DEBUG,...
John Bosman's user avatar

1
2 3 4 5
42