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
86
votes
4 answers

re.sub replace with matched content

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/:id/size If I do this in Javascript method =…
Blank
  • 4,635
  • 5
  • 33
  • 53
4
votes
3 answers

Regular expression for finding a sub-string

I am trying to find all occurances of a sub-string using regular expression. The sub-string is composed of three parts, starts with one or more 'A', followed by one or more 'N' and ended with one or more 'A'. Let a string 'AAANAANABNA' and if I…
Saikat
  • 1,209
  • 3
  • 16
  • 30
3
votes
1 answer

python regex lookbehind to remove _sublabel1 in string like "__label__label1_sublabel1"

i have dataset that prepare for train in fasttext and i wanna remove sublabels from dataset for example: __label__label1_sublabel1 __label__label2_sublabel1 __label__label3 __label__label1_sublabel4 sometext some sentce som data. Any help much…
3
votes
1 answer

Simple case folding vs full case folding in Python regex module

This is the module I'm asking about: https://pypi.org/project/regex/, it's Matthew Barnett's regex. In the project description page, the difference in behavior between V0 and V1 are stated as (note what's in bold): Old vs new behaviour In order to…
iBug
  • 35,554
  • 7
  • 89
  • 134
2
votes
0 answers

python jsonschema: Use "regex" module to validate "pattern"

I'm trying to use jsonschema for a schema which uses "pattern". However in this application, the "pattern" needs to be able to match unicode characters, which is not support by python's builtin "re" module. for example import jsonschema import…
user1751825
  • 4,029
  • 1
  • 28
  • 58
2
votes
0 answers

Why does regex require triple backslash to match a single backslash?

I was trying to match a backslash using regex and thought that this could be done by using two double backslashes, using the former to escape the latter. However, when I run the code path_str = r"\Animal_1-" Match_backslash = re.search("[\\]",…
Leo
  • 38
  • 4
2
votes
1 answer

How to timeout regex methods?

I'm using several methods of regex module. I need to set timeouts for multiple compiled patterns, but despite example from docs, I'm unable to reproduce an exception doing the following: >>> import regex >>> from time import sleep >>> def…
Kfcaio
  • 442
  • 1
  • 8
  • 20
2
votes
1 answer

How does regex.WORD affect the behavior of \b?

I'm using the PyPI module regex for regex matching. It says Default Unicode word boundary The WORD flag changes the definition of a ‘word boundary’ to that of a default Unicode word boundary. This applies to \b and \B. But nothing seems to have…
iBug
  • 35,554
  • 7
  • 89
  • 134
1
vote
2 answers

Python regular expression 'BA/BMF/ABCDEJF/

Need help with Regex expression, which i'm trying to work on. Below is the example that i'm trying to work on Code import re CommonPrefixes = [{'Prefix': 'BA/BMF/ABCDEJF/'}, {'Prefix': 'AG/CRBA_CORE/ABCDEJF/'}, {'Prefix':…
user14932992
  • 19
  • 1
  • 6
1
vote
1 answer

Extract substrings from a column of strings and place them in a list

I have the following data frame: a b x 0 id1 abc 123 tr 2 1 id2 abd1 124 tr 6 2 id3 abce 126 af 9 3 id4 abe 128 nm 12 From column b, for each item, I need to extract the substrings before the first space.…
Tipo33
  • 181
  • 13
1
vote
1 answer

Regexp twitter handle Python

I need to get twitter handle from different type of data https://twitter.com/elonmusk https://twitter.com/elonmusk/status/43940840234234 https://twitter.com/elonmusk?t=w5i1O32q6dM7usSQEaTGvA&s=09 https://twitter.com/elonmusk @elonmusk all of this…
yurasharko
  • 11
  • 1
1
vote
2 answers

Split every occurrence of Key=Value pairs in a string where the value include one or more spaces

I have a situation where user can enter commands with optional key value pairs and value may contain spaces .. here are 4 - different form user input where key and value are separated with = sign and values have space: "cmd=create-folder …
jam
  • 13
  • 4
1
vote
2 answers

Regex pattern to match a string ends with multiple charachters

I want to match a pattern that starts with $ and ends with either dot(.) or double quote("). I tried with this re.findall(r"\$(.+?)\.",query1) Above works for starting with $ and ending with . How to add OR in ending characters so that it matches…
Vikas Garud
  • 143
  • 2
  • 10
1
vote
1 answer

python - Wrong regex used?

Here is my func: @register.filter def load_human_key(key): """ load util based on typ for key return: More readable key """ regex = re.findall('[A-Z][^A-Z]*', key) if regex: joined_regex = " ".join(regex) …
mika
  • 86
  • 8
1
vote
2 answers

How to match words in a string which contain at least one vowel (a,i,o,u,e) using regex python

It seems straightforward task, but I could not solve. I am fresh at using re module string1 = 'www Cristian www Bale www' --- Here is my test string. pattern1 = '([aıoueəiöü])' --- Pattern import re string1 = 'www Cristian Bale www' pattern1 =…
1
2 3 4 5