regular expressions help
David
bouncingcats at gmail.com
Thu Sep 19 05:12:34 EDT 2019
More information about the Python-list mailing list
Thu Sep 19 05:12:34 EDT 2019
- Previous message (by thread): regular expressions help
- Next message (by thread): regular expressions help
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, 19 Sep 2019 at 18:41, Pradeep Patra <smilesonisamal at gmail.com> wrote: > On Thursday, September 19, 2019, Pradeep Patra <smilesonisamal at gmail.com> wrote: >> 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? >> 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? > I am using python 2.7.6 but I also tried on python 3.7.3. $ python2 Python 2.7.13 (default, Sep 26 2018, 18:42:22) [GCC 6.3.0 20170516] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> mystr= "where is my-dog" >>> pattern=re.compile(r'my-dog$') >>> matches = re.search(mystr) # this is syntax error, but it is what you showed above Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: search() takes at least 2 arguments (1 given) >>> matches = re.search(pattern, mystr) >>> matches.group(0) 'my-dog' >>>
- Previous message (by thread): regular expressions help
- Next message (by thread): regular expressions help
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list