python-re Questions
2
Solved
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 = "t...
7
Solved
I have a file that includes a bunch of strings like "size=XXX;". I am trying Python's re module for the first time and am a bit mystified by the following behavior: if I use a pipe for 'o...
5
Solved
Python's re match objects have .start() and .end() methods on the match object.
I want to find the start and end index of a group match. How can I do this?
Example:
>>> import re
>>&...
5
Solved
I got a little confused about Python raw string. I know that if we use raw string, then it will treat '\' as a normal backslash (ex. r'\n' would be \ and n). However, I was wondering what if I want...
1
Solved
I have a regex that might take a long time to execute, despite my best efforts at optimization. I want to be able to interrupt it in the cases where it stalls, and proceed with the rest of th...
Outspan asked 29/3, 2017 at 5:11
2
Solved
On Python 3.7 (tested on Windows 64 bits), the replacement of a string using the RegEx .* gives the input string repeated twice!
On Python 3.7.2:
>>> import re
>>> re.sub(".*", ...
4
Solved
I'm splitting a string with some separator, but want the separator matches as well:
import re
s = "oren;moish30.4.200/-/v6.99.5/barbi"
print(re.split("\d+\.\d+\.\d+", s))
print...
2
Solved
I'm wondering what is the proper way to test if a named capture group exists. Specifically, I have a function that takes a compiled regex as an argument. The regex may or may not have a specific na...
2
Solved
The list below provides examples of items and services that should not be billed separately. Please note that the list is not all inclusive.
1. Surgical rooms and services – To include surgical sui...
2
Solved
Specializing the type of re.Pattern to re.Pattern[bytes], mypy correctly detects the type error:
import re
REGEX: re.Pattern[bytes] = re.compile(b"\xab.{2}")
def check(pattern: str) ->...
Clamworm asked 25/1, 2022 at 10:16
4
Solved
I Have a list of strings like this:
stringlist = [JAN, jan, FEB, feb, mar]
And I have a dataframe that looks like this:
**date** **value**
01MAR16 1
05FEB16 12
10jan17 5
10mar15 9
03jan05 7
04APR1...
Jessamine asked 2/5, 2021 at 20:44
2
Solved
I want to make multiple substitutions to a string using multiple regular expressions. I also want to make the substitutions in a single pass to avoid creating multiple instances of the string.
Let'...
Anya asked 19/2, 2021 at 0:21
1
Can anyone tell me if I can combine flags like re.IGNORECASE, re.MULTILINE and re.DOTALL for regular expression matching?
r = re.compile(regex, re.IGNORECASE | re.MULTILINE | re.DOTALL)
I need to ...
Demonstration asked 10/2, 2021 at 15:34
1
Solved
I am learning re module for the first time but got an error .
The code-
import re
my_str='''pyhton
c++
java
c++
js node
ds algo
pyhton
js node
javac++
java
js node
ds algo'''
var = re.findall...
1
Solved
I have a python function f(foo: string) -> string. I don't write the details of the function because it could be change.
I need to get all links from markdown file and replace them with the resu...
Concavity asked 31/7, 2020 at 18:37
1
Solved
This is a spin-off from In Python, how do I split a string and keep the separators?
rawByteString = b'\\!\x00\x00\x00\x00\x00\x00\\!\x00\x00\x00\x00\x00\x00'
How can I split this rawByteString into...
Supertax asked 26/6, 2020 at 9:29
3
I'm trying to get all the links connected to each image in this webpage.
I can get all the links if I let a selenium script scroll downward until it reaches the bottom. One such link that I wish ...
Electuary asked 26/5, 2020 at 13:8
1
Solved
I am trying to escape a string such as this:
string = re.split(")(", other_string)
Because not escaping those parentheses gives me an error. But if I do this:
string = re.split("\)\(", ot...
4
Solved
Trying to get to grips with regular expressions in Python, I'm trying to output some HTML highlighted in part of a URL. My input is
images/:id/size
my output should be
images/<span>:id<...
Standfast asked 25/8, 2011 at 13:28
3
Solved
I would like to use more than one flag with the re.findall function. More specifically, I would like to use the IGNORECASE and DOTALL flags at the same time.
x = re.findall(r'CAT.+?END', 'Cat \n e...
1
Solved
The Python function re.sub(pattern, replacement, string) returns the modified string with the matched pattern replaced with the replacement. Is there any easy way to check whether a match has occur...
4
Solved
I have the output of a command in tabular form. I'm parsing this output from a result file and storing it in a string. Each element in one row is separated by one or more whitespace characters, thu...
4
I have a huge file containing the following lines DDD-1126N|refseq:NP_285726|uniprotkb:P00112 and DDD-1081N|uniprotkb:P12121, I want to grab the number after uniprotkb.
Here's my code:
x = 'unipr...
1
© 2022 - 2025 — McMap. All rights reserved.