35 questions
0
votes
0
answers
47
views
textfsm is also matching \n while matching the \w+ expected [duplicate]
I want to exterect Name and Age through ^(\w+)\n(\d+)$ and it is working.
if I use textfsm Why it is not giving data in correct format?
data:
Alice
37
Smith
41
template:
Value Names (\w+)
Value Ages (...
8
votes
2
answers
228
views
How to ignore case but not diacritics with Python regex?
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 ...
0
votes
0
answers
49
views
Python `regex` module - get unfuzzied match from fuzzy match
I an writing a simple command interpreter for a project to allow the user to interact with a virtual world. In the commands the user can refer to objects by any number of different names, and the ...
0
votes
1
answer
74
views
Python regex to match pattern if not in double quotes or equal to list of keywords
I have a regex pattern which represents a valid variable name in a language I'm trying to parse:
R'\b([A-Z][A-Z0-9_]{0,35}\b' (e.g. VAR_NAME, TABLE_READ, SOME_OTHER_VAR etc..)
However, I don't want to ...
-1
votes
1
answer
465
views
Why does the AWS Lambda function not recognize the regex library?
I am developing an AWS Lambda function where I parse some input with the regex library. Here are the code snippets where it is used:
import regex
def lambda_handler(event, context):
...
...
3
votes
0
answers
235
views
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 ...
0
votes
1
answer
157
views
Matching two consecutive outer braces and text with regex module
I am trying to create a regex that would find one or more indices of the following pattern:
some text + {text within braces} + {text within braces}
The trick is that the text within braces may ...
0
votes
1
answer
56
views
How does BestMatch findall decide how many results to return?
I'm struggling to predict how many fuzzy matches findall() will return when using regex in Python with BESTMATCH enabled:
>>> regex.findall(r'(?b)(North\ West){i<=0,s<=2,d<=1}', &...
-1
votes
1
answer
94
views
Failing to match number ranges with pattern declared in DEFINE block using PyPi regex package
I'm using https://github.com/mrabarnett/mrab-regex (via pip install regex, but experiencing a failure here:
pattern_string = r'''
(?&N)
^ \W*? ENTRY \W* (?P<...
1
vote
1
answer
256
views
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("(?P<a>a)*(?P&...
2
votes
1
answer
382
views
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:
>>> ...
1
vote
2
answers
490
views
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]...
1
vote
1
answer
1k
views
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 ...
1
vote
1
answer
35
views
Retrieve every times a group matched
Note: I'm using pypi regex module
I have the following regex pattern (flags V1 + VERBOSE):
(?(DEFINE)
(?P<id>[\d-]+)
)
id:\s(?&id)(,\s(?&id))*
How can I retrieve all the times the <...
1
vote
1
answer
113
views
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<...
1
vote
1
answer
1k
views
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 ...
1
vote
2
answers
357
views
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)Το κεφάλαιο ...
4
votes
3
answers
255
views
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 ...
1
vote
1
answer
168
views
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])...
1
vote
1
answer
166
views
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 ...
3
votes
1
answer
1k
views
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 ...
2
votes
1
answer
63
views
How does adding some text make this regex match the input even though there's no lookahead?
While working on an answer to this question, I came up with this regex:
(?:(?!\2)(?:,foo=([^,]*),(?=())|.))*\2bar=2
(Note: this regex requires the PyPI regex module)
(Short explanation: The regex ...
2
votes
1
answer
154
views
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....
2
votes
1
answer
402
views
Recursive Regex with a Pattern Matching only on Start of Match before Recursion?
I'm trying to find matching parentheses where there are also some more in the middle. I have the following regex that does that, it matches the parenthesis to find the one associated with it. What I ...
13
votes
2
answers
17k
views
Fuzzy regex (e.g. {e<=2}) correct usage in Python
I am trying to find strings which are at most two mistakes 'away' from the original pattern string (i.e. they differ by at most two letters).
However, the following code isn't working as I would ...
1
vote
1
answer
542
views
Ambiguous substring with mismatches
I'm trying to use regular expressions to find a substring in a string of DNA. This substring has ambiguous bases, that like ATCGR, where R could be A or G. Also, the script must allow x number of ...
7
votes
1
answer
3k
views
How can I find the best fuzzy string match?
Python's new regex module supports fuzzy string matching. Sing praises aloud (now).
Per the docs:
The ENHANCEMATCH flag makes fuzzy matching attempt to improve the fit
of the next match that it ...
-1
votes
1
answer
82
views
python fuzzy regex with nested or regex
I'm trying to do some fuzzy matching on a string of DNA reads. I'd like to allow for up to 1 substitution error while at the same time allowing a particular basepair to be one of two options (A or G ...
0
votes
1
answer
713
views
Fuzzy regex matching with python returns empty list
I have made a clumsy first attempt at fuzzy pattern matching using the re module in python 2.7.
Unfortunately every attempt I make returns an empty list. I simply don't understand the syntax required....
29
votes
4
answers
82k
views
Python regex, remove all punctuation except hyphen for unicode string
I have this code for removing all punctuation from a regex string:
import regex as re
re.sub(ur"\p{P}+", "", txt)
How would I change it to allow hyphens? If you could explain how you did it, that ...
3
votes
1
answer
4k
views
compiling a fuzzy regexp with python regex
When I found out that the python regex module allows fuzzy matching I was increasingly happy as it seemed as a simple solution to many of my problems.
But now I am having a problem for which I did ...
1
vote
1
answer
710
views
Using set operators with python regex module
I'm having trouble getting set operators to work in the regex module (regex 2013-11-29) in python-3.x. For example, to match ASCII characters minus punctuation I have tried:
import regex as rx
data =...
1
vote
1
answer
170
views
New regex module fuzzy function error value. Python
im trying out the fuzzy function of the new regex module. in this case, i want there to find a match for all strings with <= 1 errors, but i'm having trouble with it
import regex
statement = '...
4
votes
2
answers
1k
views
Python "regex" module: Fuzziness value
I'm using the "fuzzy match" functionality of the Regex module.
How can I get the "fuzziness value" of a "match" which indicates how different the pattern is to the string, just like the "edit ...
4
votes
1
answer
2k
views
Creating fuzzy matching exceptions with Python's new regex module
I'm testing the new python regex module, which allows for fuzzy string matching, and have been impressed with its capabilities so far. However, I've been having trouble making certain exceptions with ...