Questions tagged [python-regex]

For questions about the 3rd-party regex module, which is a replacement for the standard RE module. DO NOT use this tag if you're not using or asking about this very module. For general Python regex questions please tag [python] [regex]. If you're using the built-in RE module use the dedicated [python-re] tag.

Created by Matthew Barnett, regex is a popular 3rd-party module for matching regular expressions in Python. It is backwards-compatible with the standard re module, but offers additional functionality.

The module can be installed with pip install regex, or found in standard repositories in many Linux distros, under the name python-regex (for Python 2) or python3-regex (for Python 3).

Project home page on PyPI: https://pypi.org/project/regex/

63 questions
1
vote
3 answers

How to use Python Regex to match url

I have a string: test_string="lots of other html tags ,'https://news.sky.net/upload_files/image/2022/202209_166293.png',and still 'https://news.sky.net/upload_files/image/2022/202209_166293.jpg'" How can I get the whole 2 urls in the string,by using…
William
  • 3,724
  • 9
  • 43
  • 76
1
vote
2 answers

how to delet specific character from a list in the loop in python

this is the part of my code to retrive data from canadian stat data according to the chanpter and save them in the excel form then open these excel form and change them and save it in the text form. the problem for me is that in the first column I…
Saeid Vaygani
  • 179
  • 1
  • 1
  • 8
1
vote
0 answers

Python regex to find servers and print to a csv file

Trying to create a python script that finds all the servers that sent email and output the results in a .csv file, with one column being the server name and the other column being the server IP address, with no repeats in the server name or IP…
Kusanagi97
  • 23
  • 7
1
vote
1 answer

Regex - negative lookbehind for any character excluding pure whitespace

I'm trying to write a regex pattern that will fail a match if the preceding pattern contains any character except pure whitespace, for example --hello (match) --goodbye (match) ROW_NUMBER() OVER (ORDER BY DATE) --date (fail) --comment with some…
RoyalSwish
  • 1,503
  • 10
  • 31
  • 57
1
vote
1 answer

Python regex groupDict with repetitions of groups

Wondering if there is a function such as match.groupdict() that catches repetition similar to match.captures function. When I run this code: import regex test = regex.compile("(?Pa)*(?Pb)*(?Pc)*") test.match("aabbbcc").groupdict() I…
ajreckof
  • 70
  • 5
1
vote
2 answers

Python regex to match a person's height

I am trying to create a python regex that will match a person's height, in feet and inches, separated by a single apostrophe (such as 6'0 for example). Valid heights are between 4'0 and 6'11 for my purposes: Here's what I have so far: import…
Cullen M.
  • 11
  • 1
1
vote
2 answers

re.findall -> RegEx in Python

import regex frase = "text https://www.gamivo.com/product/sea-of-thieves-pc-xbox-one other text https://www.gamivo.com/product/fifa-21-origin-eng-pl-cz-tr" x = regex.findall(r"/((http[s]?:\/\/)?(www\.)?(gamivo\.com\S*){1})", frase)…
Diego
  • 25
  • 2
1
vote
1 answer

Regex Replace Words Containing Specified Substring

I am trying to replace words in my string that contain a certain substring. Here is an example import regex as re given_in = 'My cat is not like other cats' desired_out = 'My foo is not like other foo' I have tried print(re.sub('cat', 'foo',…
emilaz
  • 1,722
  • 1
  • 15
  • 31
1
vote
1 answer

How to refer to a named capturing group in the Python PyPi regex pattern

As the title reads, we can easily match nested parentheses in regex with e.g. (\(((?:[^()]+|(?1))+)) which will match balanced parentheses. How can we use a named subgroup instead, as e.g. in (?P\(((?:[^()]+|(?\g))+)) I'm not looking for…
Jan
  • 42,290
  • 8
  • 54
  • 79
1
vote
1 answer

regex with repeated group names

I'm trying to make a regex where I have some duplicated group names, for instance, in the example below I want to find the values of ph, A and B such that if I replace them in the pattern, I retrieve string. I do this using regex, as the default re…
dhokas
  • 1,771
  • 2
  • 13
  • 22
1
vote
2 answers

Matching in a fuzzy manner a number in Python

I have the following problem: I have strings that contain numbers that may include dots or commas. E.g.: text = 'ην Θεσσαλονίκη και κατοικεί στην Καλαμαριά Θεσσαλονίκης, (οδός Επανομής 32)Το κεφάλαιο της εταιρείας ορίζεται στο ποσό των δέκα…
user8270077
  • 4,621
  • 17
  • 75
  • 140
1
vote
1 answer

How to remove all emoji (unicode) characters from a string python

I have the following string: tweet = "Get $10 worth of AMAL!!\\nThis campaign will be final AirDrop before official release!!\\nhttps://form.run/@airdrop-e\xa0\\n\\nRT please!\\n\\n#amanpuri #AMAL\\n#BTC #XRP #ETH \\n#cryptocurrency \\n#China…
Ivan
  • 27
  • 6
1
vote
1 answer

How can I use a recursive regex or another method to recursively validate this BBcode-like markup in Python?

I am attempting to write a program that validates documents written in a markup language similar to BBcode. This markup language has both matching ([b]bold[/b] text) and non-matching (today is [date]) tags. Unfortunately, using a different markup…
1
vote
1 answer

Python regexes: matching parentheses in newest version (Feb 2019)

1. About Python regex 2019.02.21 Python is upgrading the regex module. The latest release is from Feb 21, 2019. You can consult it here: https://pypi.org/project/regex/ It will replace the re module in time. For now, you need to install it manually…
K.Mulier
  • 8,069
  • 15
  • 79
  • 141
0
votes
1 answer

How to neglect a backslash of the text while using regular expression re.search in python?

import re a = "apple\c" b = "applec" re.search(pattern, a) re.search(pattern, b) while searching the pattern. In example ".+" for Any char one or more reptitions. Here I want to neglect "\" when ".+" identify "\" character in search.