Skip to content

Lab 03, task 7 #1

Open
Open

Description

@sevinjyolchuyeva

I wrote this task as below:
s='hey (come) go'
re.sub('[(].*?[)]', '', s)

The output is: 'hey go'

But if s='hey (come) go (flat)' then the 'go' is deleted too.
How can I write code that output should be 'hey go'

Activity

  1. DavidNemeskey commented on Sep 27, 2017

    @DavidNemeskey
    Collaborator

    I just tried the second substitution and it does what it ought to do: it returns 'hey go '. go would only be deleted if you omitted the question mark:

    In [1]: import re
    
    In [2]: re.sub('[(].*?[)]', '', 'hey (come) go (flat)')
    Out[2]: 'hey  go '
    
    In [3]: re.sub('[(].*[)]', '', 'hey (come) go (flat)')
    Out[3]: 'hey '
  2. sevinjyolchuyeva commented on Sep 27, 2017

    @sevinjyolchuyeva
    Author

    Yes, you are right :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions