3

I'm trying to a get a JSON string from another string with this regex:

YAHOO.Finance.SymbolSuggest.ssCallback\((.*?)\)

It works on regex101.com, but when I use it in my code:

import re
import json
import requests

def stock_lookup(name):

    url = "http://autoc.finance.yahoo.com/autoc?query={0}&callback=YAHOO.Finance.SymbolSuggest.ssCallback".format(name)

    response = requets.get(url)

    json_data = json.loads(re.match(data,"YAHOO.Finance.SymbolSuggest.ssCallback\((.*?)\)"))


    return json_data

I get this error:

sre_constants.error: bad character range

Thanks in advance

1 Answer 1

1

You misplaced the arguments in the match method, regex should come first.

re.match("YAHOO.Finance.SymbolSuggest.ssCallback\((.*?)\)", data)

re.match documentation:

re.match(pattern, string, flags=0)

The error is shown because most probably there is some z-A type of range in the data.

Sign up to request clarification or add additional context in comments.

3 Comments

Aahaha thanks a lot. I think i left my brain somewhere
Maybe you also code in C#, where Regex.Match accepts input string as the 1st argument, and the pattern as the 2nd. The issue is not so uncommon.
Not wrong, i just got the example from C# code even though ain't a C# Programmer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.