This question already has answers here:
Use Python Match object in string with backreferences
(1 answer)
Regex in python: is it possible to get the match, replacement, and final string?
(2 answers)
Closed 3 years ago.
What is an example usage of Match.expand ? It doesn't give any examples in the python docs (which is the first I've heard of the method), and only states:
Match.expand(template)
Return the string obtained by doing backslash substitution on the template string template, as done by the sub() method.
How would this actually be used and how could it be useful?
you can find more explanations and examples here:
match.expand
In general:
it allows you to expand the match you have found and modify its' prefix
Related
This question already has answers here:
Reuse part of a Regex pattern
(6 answers)
Is it possible to define a pattern and reuse it to capture multiple groups?
(1 answer)
Closed 2 years ago.
I'm trying to match strings of the form:
"FLOAT:FLOAT:FLOAT"
where:
FLOAT="(\d*\.\d*)"
I would like to not repeat code. (eg. "(\d*\.\d*):(\d*\.\d*):(\d*\.\d*)")
Is there support for this in regex? Or is this typically done with string manipulation (.format())?
I'm using python, but I'm interested in other flavors of regex as well.
This question already has answers here:
How can I selectively escape percent (%) in Python strings?
(6 answers)
Closed 6 years ago.
In the sec2time() Python function provided by Lee he uses a syntax I'm struggling to understand:
pattern = '%%02d:%%02d:%%0%d.%df' % (n_msec+3, n_msec)
What is the %%here and how does it affect the outcome?
The % in that string introduces replaceable parts as at the end %d.%df. If you want a % in the output you have to do something special, in this case use %%
After these substitustions the resulting pattern will look like:
'%02d:%02d:%0123.120f'
which, among other things an be used for further substitution.
In the documentation, at the bottem of the second table in that section, it states:
'%' No argument is converted, results in a '%' character in the result.
This question already has answers here:
Python regex -- extraneous matchings
(5 answers)
Closed 6 years ago.
I searched in all the internet and didnt get a good answer on this thing.
What parentheses in python are stand for? its very wierd..
For example, if i do:
re.split(r'(/s*)', "ho from there")
its will give me a list of separate words with the spaces between that... how does its happening?
This isn't specific to python, but in regex those denote a capture group.
Further information on how these are handled in re.split can be seen here
This question already has answers here:
How can I get the next string, in alphanumeric ordering, in Python?
(4 answers)
Closed 6 years ago.
If Python has an implementation of Ruby's next method? I mean something what works exactly the same as in Ruby, so if I type e.g. "z".next it will return "aa" (instead of just next sign in ascii table), "az".next will return "ba" and so on.
I don't believe there is a built-in method for this in Python. A similar question was asked on How can I get the next string, in alphanumeric ordering, in Python? and the accepted answer gives a solution.
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 4 years ago.
I am trying to match regular expression using python in this code.
CDS_REGEX = re.compile(r'\+CDS:\s*"([^"]+)",\s*(\d+)$')
cdsiMatch = allLinesMatchingPattern(self.CDS_REGEX, notificationLine)
print cdsiMatch
Matching String:
['+CDS: 24', '079119890400202306A00AA17909913764514010106115225140101061452200']
Please help me i am not able to find my mistake,
As #Blckknght said, are you sure you really want to match that string?
What is ([^"]+) supposed to match?
You're looking for " instead of ' (you probably want ['"]).
You're only checking for numbers here: (\d+), but your long string clearly contains A's.