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...
Developing asked 25/7, 2024 at 23:12

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...
Louisiana asked 25/8, 2013 at 3:31

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 >>&...
Kiangsu asked 11/4, 2021 at 16:2

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...
Hoxsie asked 4/2, 2013 at 15:5

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(".*", ...
Feeding asked 15/2, 2019 at 16:40

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...
Translucent asked 7/9, 2022 at 9:14

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...
Catharine asked 1/3, 2022 at 13:26

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...
Underestimate asked 31/1, 2022 at 20:0

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...
Arturoartus asked 27/8, 2020 at 11:14

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...
Joist asked 29/4, 2020 at 8:24

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&lt...
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...
Babita asked 4/6, 2015 at 18:18

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...
Inhalator asked 29/5, 2013 at 1:37

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...
Freak asked 11/6, 2012 at 5:40

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...
Mitre asked 25/9, 2011 at 21:19
1

© 2022 - 2025 — McMap. All rights reserved.