Regex Quantifiers in Python (trying to match a group)
The second & third regex allows the empty string ''
to be matched.
re.search
is merely returning the first match as documented: https://docs.python.org/3/library/re.html#re.search
python regex re.compile and re.search
You'll need another quantifier, namely a +
:
import re
real_comp = re.compile(r'([0-9]+)')
print(real_comp.search('+123i').group())
Which yields
123
Otherwise the regex engine reports a match before the very first consumed char ( [0-9]*
is always true).
Related Topics
Pivot String Column on Pyspark Dataframe
Using Monotonically_Increasing_Id() for Assigning Row Number to Pyspark Dataframe
Nested Ssh Session with Paramiko
Open Cv Error: (-215) Scn == 3 || Scn == 4 in Function Cvtcolor
Python Decorator Handling Docstrings
Writing to a File in a for Loop Only Writes the Last Value
Making a Python User-Defined Class Sortable, Hashable
Installing MySQL Python on MAC Os X
Nameerror: Global Name 'Xrange' Is Not Defined in Python 3
Scikit-Learn Gridsearchcv with Multiple Repetitions
Convert Year/Month/Day to Day of Year in Python
Numpy to Tfrecords: Is There a More Simple Way to Handle Batch Inputs from Tfrecords
Convert Pandas Datetimeindex to Unix Time