Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38302
| From | rh <richard_hubbe11@lavabit.com> |
|---|---|
| Subject | Curious to see alternate approach on a search/replace via regex |
| Date | 2013-02-06 13:41 -0800 |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1425.1360186878.2939.python-list@python.org> (permalink) |
I am curious to know if others would have done this differently. And if so
how so?
This converts a url to a more easily managed filename, stripping the
http protocol off.
This:
http://alongnameofasite1234567.com/q?sports=run&a=1&b=1
becomes this:
alongnameofasite1234567_com_q_sports_run_a_1_b_1
def u2f(u):
nx = re.compile(r'https?://(.+)$')
u = nx.search(u).group(1)
ux = re.compile(r'([-:./?&=]+)')
return ux.sub('_', u)
One alternate is to not do the compile step. There must also be a way to
do it all at once. i.e. remove the protocol and replace the chars.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Curious to see alternate approach on a search/replace via regex rh <richard_hubbe11@lavabit.com> - 2013-02-06 13:41 -0800
Re: Curious to see alternate approach on a search/replace via regex Roy Smith <roy@panix.com> - 2013-02-06 16:54 -0500
Re: Curious to see alternate approach on a search/replace via regex Nick Mellor <thebalancepro@gmail.com> - 2013-02-07 04:53 -0800
Re: Curious to see alternate approach on a search/replace via regex rh <richard_hubbe11@lavabit.com> - 2013-02-07 21:47 -0800
Re: Curious to see alternate approach on a search/replace via regex Nick Mellor <thebalancepro@gmail.com> - 2013-02-08 00:53 -0800
Re: Curious to see alternate approach on a search/replace via regex Nick Mellor <thebalancepro@gmail.com> - 2013-02-08 00:53 -0800
Re: Curious to see alternate approach on a search/replace via regex Nick Mellor <thebalancepro@gmail.com> - 2013-02-07 04:53 -0800
csiph-web