regular expressions help

Barry Scott barry at barrys-emacs.org
Fri Sep 20 14:02:10 EDT 2019


When I'm debugging a regex I make the regex shorter and shorter to figure out
what the problem is.

Try starting with re.compile(r'm') and then add the chars one by one seeing
what happens as the string gets longer.

Barry


> On 19 Sep 2019, at 09:41, Pradeep Patra <smilesonisamal at gmail.com> wrote:
> 
> I am using python 2.7.6 but I also tried on python 3.7.3.
> 
> On Thursday, September 19, 2019, Pradeep Patra <smilesonisamal at gmail.com>
> wrote:
> 
>> Beginning of the string. But I tried removing that as well and it still
>> could not find it. When I tested at www.regex101.com and it matched
>> successfully whereas I may be wrong. Could you please help here?
>> 
>> On Thursday, September 19, 2019, David <bouncingcats at gmail.com> wrote:
>> 
>>> On Thu, 19 Sep 2019 at 17:51, Pradeep Patra <smilesonisamal at gmail.com>
>>> wrote:
>>>> 
>>>> pattern=re.compile(r'^my\-dog$')
>>>> matches = re.search(mystr)
>>>> 
>>>> In the above example both cases(match/not match) the matches returns
>>> "None"
>>> 
>>> Hi, do you know what the '^' character does in your pattern?
>>> 
>> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 




More information about the Python-list mailing list