amza
amza

Reputation: 810

Python re.search() not returning anything

Here is my code snippet:

elif outputLn.startswith ('GET'):
            regex = '(.*)Packages(Id=\'' + self.m_name + '(.*))'
            nugetOutput.append(re.search(regex, outputLn).group().replace('\n', ''))

So my outputLn is

"GET https://www.nuget.org/api/v2/Packages(Id='Prism.PubSubEvents',Version='1.0.0')\r\n"

And my regex is this:

(.*)Packages(Id='Prism.PubSubEvents(.*))

What i want is that if the input line matches this pattern to put it in the arrary (but I have to take the \n off as well). Why is this not working? Currently it is returning None.

Upvotes: 0

Views: 134

Answers (1)

jwodder
jwodder

Reputation: 57470

You forgot to escape the "middle" set of parentheses:

(.*)Packages\(Id='Prism.PubSubEvents(.*)\)
            ^ escape this               ^ and this

Upvotes: 3

Related Questions