regular expressions help

Pradeep Patra smilesonisamal at gmail.com
Thu Sep 19 11:05:55 EDT 2019


Thanks  David /Anthony for your help. I figured out the issue myself. I
dont need any ^, $ etc to the regex pattern and the plain string (for exp
my-dog) works fine. I am looking at creating a generic method so that
instead of passing my-dog i can pass my-cat or blah blah. I am thinking of
creating a list of probable combinations to search from the list. Anybody
have better ideas?

On Thu, Sep 19, 2019 at 3:46 PM David <bouncingcats at gmail.com> wrote:

> On Thu, 19 Sep 2019 at 19:34, Pradeep Patra <smilesonisamal at gmail.com>
> wrote:
>
> > Thanks David for your quick help. Appreciate it. When I tried on python
> 2.7.3 the same thing you did below I got the error after matches.group(0)
> as follows:
> >
> > AttributeError: NoneType object has no attribute 'group'.
> >
> > I tried to check 'None' for no match for re.search as the documentation
> says but it's not working.
> >
> > Unfortunately I cannot update the python version now to 2.7.13 as other
> programs are using this version and need to test all and it requires more
> testing. Any idea how I can fix this ? I am ok to use any other re
> method(not only tied to re.search) as long as it works.
>
> Hi again Pradeep,
>
> We are now on email number seven, so I am
> going to try to give you some good advice ...
>
> When you ask on a forum like this for help, it is very
> important to show people exactly what you did.
> Everything that you did. In the shortest possible
> way that demonstrates whatever issue you are
> facing.
>
> It is best to give us a recipe that we can follow
> exactly that shows every step that you do when
> you have the problem that you need help with.
>
> And the best way to do that is for you to learn
> how to cut and paste between where you run
> your problem code, and where you send your
> email message to us.
>
> Please observe the way that I communicated with
> you last time. I sent you an exact cut and paste
> from my terminal, to help you by allowing you to
> duplicate exactly every step that I made.
>
> You should communicate with us in the same
> way. Because when you write something like
> your most recent message
>
> > I got the error after matches.group(0) as follows:
> > AttributeError: NoneType object has no attribute 'group'.
>
> this tells us nothing useful!! Because we cannot
> see everything you did leading up to that, so we
> cannot reproduce your problem.
>
> For us to help you, you need to show all the steps,
> the same way I did.
>
> Now, to help you, I found the same old version of
> Python 2 that you have, to prove to you that it works
> on your version.
>
> So you talking about updating Python is not going
> to help. Instead, you need to work out what you
> are doing that is causing your problem.
>
> Again, I cut and paste my whole session to show
> you, see below. Notice that the top lines show that
> it is the same version that you have.
>
> If you cut and paste my commands into
> your Python then it should work the same way
> for you too.
>
> If it does not work for you, then SHOW US THE
> WHOLE SESSION, EVERY STEP, so that we can
> reproduce your problem. Run your python in a terminal,
> and copy and paste the output you get into your message.
>
> $ python
> Python 2.7.3 (default, Jun 20 2016, 16:18:47)
> [GCC 4.7.2] 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(pattern, mystr)
> >>> matches.group(0)
> 'my-dog'
> >>>
>
> I hope you realise that the re module has been used
> by thousands of programmers, for many years.
> So it's extremely unlikely that it "doesn't work" in a way that
> gets discovered by someone who hardly knows how to use it.
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list