Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74034
| From | Roy Smith <roy@panix.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Question about metacharacter '*' |
| Date | 2014-07-06 12:47 -0400 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <roy-279E10.12473806072014@news.panix.com> (permalink) |
| References | <3f7ecf04-b881-4e79-aa59-893580090468@googlegroups.com> <CABicbJKUOsKW77LGkDF-1E52AmsPpTJq=GAUTA2PLpff+7fxNQ@mail.gmail.com> <53B96C0A.3030302@mrabarnett.plus.com> <mailman.11545.1404662273.18130.python-list@python.org> <d8f8d76d-0a47-4f59-8f09-da2a44cc1d2e@googlegroups.com> |
In article <d8f8d76d-0a47-4f59-8f09-da2a44cc1d2e@googlegroups.com>,
Rick Johnson <rantingrickjohnson@gmail.com> wrote:
> As an aside i prefer to only utilize a "character set" when
> nothing else will suffice. And in this case r"[0-9][0-9]*"
> can be expressed just as correctly (and less noisy IMHO) as
> r"\d\d*".
Even better, r"\d+"
>>> re.search(r'(\d\d*)', '111aaa222').groups()
('111',)
>>> re.search(r'(\d+)', '111aaa222').groups()
('111',)
Oddly enough, I prefer character sets to the backslash notation, but I
suppose that's largely because when I first learned regexes, that
new-fangled backslash stuff hadn't been invented yet. :-)
I know I've said this before, but people should put more effort into
learning regex. There are lots of good tools in Python (startswith,
endswith, split, in, etc) which handle many of the most common regex use
cases. Regex is also not as easy to use in Python as it is in a
language like Perl where it's baked into the syntax. As a result,
pythonistas tend to shy away from regex, and either never learn the full
power, or let their skills grow rusty. Which is a shame, because for
many tasks, there's no better tool.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Question about metacharacter '*' rxjwg98@gmail.com - 2014-07-06 04:51 -0700
Re: Question about metacharacter '*' Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-07-06 05:09 -0700
Re: Question about metacharacter '*' rxjwg98@gmail.com - 2014-07-07 11:51 -0700
Re: Question about metacharacter '*' Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-07-07 13:27 -0700
Re: Question about metacharacter '*' Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-07-07 22:50 +0100
Re: Question about metacharacter '*' MRAB <python@mrabarnett.plus.com> - 2014-07-06 16:32 +0100
Re: Question about metacharacter '*' Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-07-06 08:50 -0700
Re: Question about metacharacter '*' Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 09:24 -0700
Re: Question about metacharacter '*' Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 09:32 -0700
Re: Question about metacharacter '*' Roy Smith <roy@panix.com> - 2014-07-06 12:47 -0400
Re: Question about metacharacter '*' Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 10:38 -0700
Re: Question about metacharacter '*' Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 10:58 -0700
csiph-web