Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #99762

Re: I can't understand re.sub

From Erik <python@lucidity.plus.com>
Newsgroups comp.lang.python
Subject Re: I can't understand re.sub
Date 2015-12-01 01:26 +0000
Message-ID <mailman.49.1448933226.14615.python-list@python.org> (permalink)
References <af27abe4-f81e-4d44-a504-c58d9e71986a@googlegroups.com> <mailman.26.1448872519.14615.python-list@python.org> <lf54mg3eupq.fsf@ling.helsinki.fi>

Show all headers | View raw


On 30/11/15 08:51, Jussi Piitulainen wrote:
> Surely the straight thing to say is:
>
>     >>> foo.replace(' CONTENT_PATH ', ' Substitute ')
>     'foo bar baz spam Substitute bar spam'

Not quite the same thing (but yes, with a third argument of 1, it would be).

> But there was no guarantee of spaces around the target.

I know. It was just an example to show that there might be an option 
that's not a regex for the specific use indicated. It's up to the OP to 
decide whether they think the spaces (or any other, or no, delimiter) 
would actually be required or useful. Or whether they really prefer a 
regex after all.

> If you wish to,
> say, replace "spam" in your foo with "REDACTED" but leave it intact in
> "May the spammer be prosecuted", a regex might be attractive after all.

But that's not what the OP said they wanted to do. They said everything 
was very fixed - they did not want a general purpose human language text 
processing solution ... ;)

E.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

I can't understand re.sub Mr Zaug <matthew.herzog@gmail.com> - 2015-11-29 13:36 -0800
  Re: I can't understand re.sub Denis McMahon <denismfmcmahon@gmail.com> - 2015-11-29 22:01 +0000
    Re: I can't understand re.sub Mr Zaug <matthew.herzog@gmail.com> - 2015-11-29 17:20 -0800
  Re: I can't understand re.sub Rick Johnson <rantingrickjohnson@gmail.com> - 2015-11-29 17:12 -0800
    Re: I can't understand re.sub Mr Zaug <matthew.herzog@gmail.com> - 2015-11-29 17:24 -0800
  Re: I can't understand re.sub Erik <python@lucidity.plus.com> - 2015-11-29 21:53 +0000
    Re: I can't understand re.sub Jussi Piitulainen <harvesting@is.invalid> - 2015-11-30 10:51 +0200
      Re: I can't understand re.sub Erik <python@lucidity.plus.com> - 2015-12-01 01:26 +0000
        Re: I can't understand re.sub Jussi Piitulainen <harvesting@is.invalid> - 2015-12-01 07:28 +0200
          Re: I can't understand re.sub Erik <python@lucidity.plus.com> - 2015-12-01 21:31 +0000

csiph-web