0

First time posting and having an issue with Matching text using ICU Regex. I'm using the workflow for iOS app and trying to create a workflow for stocks using yahoo finance partially because I need to get OTC stock data.

From this URL, you get:

{"query":{"count":1,"created":"2015-01-10T22:39:34Z","lang":"en-us","results":{"row":{"col0":"MINERCO RES INC","col1":"0.0072"}}}}

The workflow I'm creating will ask for a company name and insert it into the Url above so what I'm trying to do is pull the col1:0.0072 Important to note the price which in this example is 0.0072 can and will change often and eventually I want to be able to add more fields and pull related data (ex: col2:date).

I have a workaround that doesn't use Regex but makes the workflow incredibly long when adding extra data sets. Someone else posted a stock workflow and used a different site other than yahoo and simply used \{.*\} however that site returned the stock in quotes but the price wasn't in quotes whereas yahoo shows both stock and price in quotes and that code doesn't work. Also the site he used doesn't work with OTC stocks

The app only takes Straight ICU Regex to my knowledge so can't really do half the Regex examples out there for other languages.

I've spent hours on this and half the time was using incorrect syntax as I only recently found out it takes ICU Regex (NSRegularExpression type)and half the examples I tried were wrong.

The original workflow I'm modifying used this as their URL: http://dev.markitondemand.com/Api/v2/Quote/jsonp?symbol=AAPL

And the resulted output was:

(function () { })({"Status":"SUCCESS","Name":"Apple Inc","Symbol":"AAPL","LastPrice":112.01,"Change":0.120000000000005,"ChangePercent":0.107248190186795,"Timestamp":"Fri Jan 9 15:59:00 UTC-05:00 2015","MSDate":42013.6659722222,"MarketCap":656920728400,"Volume":4934490,"ChangeYTD":110.38,"ChangePercentYTD":1.47671679652112,"High":113.25,"Low":110.22,"Open":112.71})

And that was the code where his: \{.*\} worked with "Match Text" which then he used a get dictionary from input which can parse sets from JSON (JSON (like {"foo": "bar"}) and key-value pairs (like foo=bar&baz=biz) are supported in this function).

So I just wanted a short code like what he used versus the current workaround I'm using which takes an additional seven steps per item it pulls so seven steps for stock name and seven steps for stock price....

Jolta
  • 2,620
  • 1
  • 29
  • 42
Jason G
  • 13
  • 4
  • 3
    why are you trying to parse json with regex?? – tenub Jan 13 '15 at 18:46
  • the Workflow I'm modifying used a function within the app "Get dictionary from input" which as defined within the app means: Make a dictionary from the text passed as input. JSON (like {"foo": "bar"}) and key-value pairs (like foo=bar&baz=biz) are supported. Input: Dictionaries Result: Dictionaries – Jason G Jan 14 '15 at 00:59
  • How about using a Json parsing library instead? It will be more stable when the format inevitably changes. – Jolta Feb 25 '15 at 15:58

1 Answers1

1

I finally figured it out. The code I needed was: 'col1+.*(\d)' and I needed to add two replay texts one for '":"' with '=' and another replace '","' with '$' and it worked and is extensible by assigning additional "get value for key"'s. EDIT: my code within single quotes isn't showing correctly so take note if anyone wants to copy and use my code.

Jason G
  • 13
  • 4