Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82164
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Denis McMahon <denismfmcmahon@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Python re.search simple question |
| Date | Tue, 9 Dec 2014 00:31:58 +0000 (UTC) |
| Organization | A noiseless patient Spider |
| Lines | 25 |
| Message-ID | <m65ftu$hu3$1@dont-email.me> (permalink) |
| References | <mailman.16710.1418021565.18130.python-list@python.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Tue, 9 Dec 2014 00:31:58 +0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="66ffcfa4470a58bcddbdcd1913f98ab4"; logging-data="18371"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX188hRMgq6BkO89lxsD+pjILmHUyaI8K/6Q=" |
| User-Agent | Pan/0.136 (I'm far too busy being delicious; GIT 926a150 git://git.gnome.org/pan2) |
| Cancel-Lock | sha1:ICD9jr0RReYTydhRG8eyCVn06CU= |
| Xref | csiph.com comp.lang.python:82164 |
Show key headers only | View raw
On Mon, 08 Dec 2014 12:22:37 +0530, Ganesh Pal wrote:
>>>> pattern
> 'Token-based migrations cannot be mixed with level-based: [prev 0 , now
> 1]'
Because [] defines a character class in a regex, if you want literal
[ and ] you need to escape them with backslash.
[prev 0 , now 1] -> match any single character from the set "prev0,now1 "
\[prev 0 , now 1\] -> match the actual text [prev 0 , now 1]
Try these:
re.search('[prev 0 , now 1]','p') # matches (p in "prev0,now1 ")
re.search('[prev 0 , now 1]','x') # doesn't match (x not in "prev0,now1 ")
re.search('\[prev 0 , now 1\]','p') # doesn't match
re.search('\[prev 0 , now 1\]','[prev 0 , now 1]') # matches
--
Denis McMahon, denismfmcmahon@gmail.com
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Python re.search simple question Ganesh Pal <ganesh1pal@gmail.com> - 2014-12-08 12:22 +0530
Re: Python re.search simple question Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2014-12-08 09:08 +0200
Re: Python re.search simple question Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2014-12-08 09:13 +0200
Re: Python re.search simple question Denis McMahon <denismfmcmahon@gmail.com> - 2014-12-09 00:31 +0000
csiph-web