Split string with lookahead regex - regex

I have this string:
{"TimePeriod": {"Start": "2017-03-01", "End": "2017-04-01"}, "Total": {"UnblendedCost": {"Amount": "2942.25119998", "Unit": "USD"}, "UsageQuantity": {"Amount": "20835", "Unit": "Hrs"}}, "Groups": [], "Estimated": false},
{"TimePeriod": {"Start": "2017-04-01", "End": "2017-05-01"}, "Total": {"UnblendedCost": {"Amount": "2982.62609983", "Unit": "USD"}, "UsageQuantity": {"Amount": "21049", "Unit": "Hrs"}}, "Groups": [], "Estimated": false},
{"TimePeriod": {"Start": "2017-05-01", "End": "2017-06-01"}, "Total": {"UnblendedCost": {"Amount": "1399.04829988", "Unit": "USD"}, "UsageQuantity": {"Amount": "23010", "Unit": "Hrs"}}, "Groups": [], "Estimated": false},
{"TimePeriod": {"Start": "2017-06-01", "End": "2017-07-01"}, "Total": {"UnblendedCost": {"Amount": "962.47549987", "Unit": "USD"}, "UsageQuantity": {"Amount": "20049", "Unit": "Hrs"}}, "Groups": [], "Estimated": false}
I am working on a regex to split the above string into multiple records, e.g: each record will look like:
{"TimePeriod": {"Start": "2017-06-01", "End": "2017-07-01"}, "Total": {"UnblendedCost": {"Amount": "962.47549987", "Unit": "USD"}, "UsageQuantity": {"Amount": "20049", "Unit": "Hrs"}}, "Groups": [], "Estimated": false}
My current approach is
(\{\"TimePeriod\":){1}.+(false\}){1}
But this will match the entire string instead of matching each record, I think the solution should be something with the lookahead in regex to ensure the TimePeriod appears just once in the matched string but I don't know how to do it. Any pointers will be appreciated.
*There is no newline between each line, I just put it there for the presentation

This seems work for your need. I just only slightly changed your regex to lazy searching mode.+? from greed .+
(\{\"TimePeriod\":){1}.+?(false\}){1}
Demo
And if some more modification is added, it would be
(\{\"TimePeriod\":).+?(false\})
Another method using lookahead,
(\{\"TimePeriod\":)(?:(?!false).)+(false\})

You may split on the following lookaround:
,(?=\{"TimePeriod":)
Demo
The logic basically says to split at a point where there is a comma immediately followed by the text {"TimePeriod":. Note that this means that there would not be a split at the very start of the text because there is no comma.

Related

How do I use aggregates in grouped marks?

I'm trying to use the min and max aggregates of a quantitative column (Total bombers) grouped by another column (Country) in a rule mark of my visual. I want the rule y property to start at the minimum value of Total bombers and the rule y2 property to end at the maximum value of total bombers, but I can't seem to find the right syntax for the min and max aggregates of the rule mark. I can get the result I'm looking for by not grouping the marks but I would like to implement it for grouped marks so I can re-use it more easily.
Spec for grouped version I'm trying to use min and max aggregates in:
https://vega.github.io/editor/#/url/vega/N4IgJAzgxgFgpgWwIYgFwhgF0wBwqgegIDc4BzJAOjIEtMYBXAI0poHsDp5kTykSArJQBWENgDsQAGhAATONABONHJnaT0AQQAETJBBpRtAGxri422EkWZtcAB5IEOY3ErSQAdxqz6aAQAMATLwNGRYaABMQTI4SLKyZmT+MgZk4kjGEGgA2gC6MrJImCioOaAZCHBoIExsCExwitkyDIrGNVi4+ES0EJjUdIxMDBBNUBKYcOIDEwgkssRsbIryigQCTADMAQCcuwDssgAcBwHHCUgHx1tMTJFMuwKykXC7cABmWwAsBIpIngIACF6o1FABSSICaIAcSQOEoUAgxA8HxWyEwaFAmAAnjhqugkSjYtYxliQAAVNglYy6UFNbLocQMBpNDwATTg1hqzNZihAAF8BTJMP9xBA0YoELlsXiCSBJQgGMYUDJ9DUilMPA4cPz0GoqgAKTVwA1wY3FFmUTnWKTaACMdvtAEpnYKpLL8TUPjRjFN+TIdXq5JaENauYptAAeAC8Dt2xwCgryAoKIGgmQUMpAlXl9g8uK9+poVQ8YrI8u8vhgHlk9SQZnJmtKtXpzVRNDgxlkGuK1SFHpzTnlOILcpqpnM3Jk5floXCmJk4kMBNFDDgMgAXk02Gg1xu5PXG6hQM2anU+S0FZ3uzUqTS6ZfBcKKsOahNjCsx0WQCtEhkOhnJBxArd8+zIFZR0KI8NFPYoWwvMErx9Lse3QABhNgGBmRRRyFNMkHsLMylAFZOxmc9qUweoPAzVwanzF9f2UaZMXQVwPkXdMoEzGo8LTZBFAAa0ZcoQELeUyEULCcFRaTpRPBUkCgU1yVzGoxhYq8z3QRCGQ8KSZKYUcMKwnC8OFEBBJE7N5CUFQ1AkGoABkzAsSU7CWYwGEc8RtDYD5tGoh89OaXQcUsMzRSg8Tx3Yty5JoxSdPTJpO2ySzpgmeRyVYtlFPzRS6LzDtUN7LVLJM0Bir40rb3Qe9MkfJD3XTUU2CEglqp4+jCTYT8A2vMrTOw6LWv6aTOvQ+FyWITJ1xqaTsJ7SyJo6uAAHUfD8RS5u8gktlW9rOoAeTiKA6CqkA9oW1AAkoAQhQHU8FCgZRVHUGoAAU2DMTAIG0Dzgqa0KAeMyLRtw795QgHEGn6xKFLgkoNLSrNMvEbKupAPK9VAQrut49B8xkFD6pDCqZCumr0Bism0MpakQbbDLUhobdZvmglAksn1jA6IqevlD8v1Jm8GcwyG8NSY7Nu2mtdq5qIAiOybsZu+VTAXCAhJxJh9ufVocBNck+eMM7lMuzmDdQe1VfWi2Ltxa3bpVyyYDYUg8batXHatxWbbtp7Bzst6HM+9AACVlQZXRTU8OBpgh8ygqZ2lQu0XkWpFOKQEUGPEabeDUa01qsrYHLFIYY2+3JAnuKJkASaG8mTcq8kaZAOnxbvNPmv0yrIhdglohVmW1eHicwiwHW9YN+3Oq26tJ9QQ7x4d87-dADW0Hux6npTFMgA
Spec for non-grouped version that achieves what I want to do:
https://vega.github.io/editor/#/url/vega/N4IgJAzgxgFgpgWwIYgFwhgF0wBwqgegIDc4BzJAOjIEtMYBXAI0poHsDp5kTykSArJQBWENgDsQAGhAATONABONHJnaT0AQQAETJBBpRtAGxri422EkWZtcAB5IEOY3ErSQAdxqz6aAQAMATLwNGRYaABMQTI4SLKyZmT+MgZk4kjGEGgA2gC6MrJImCioOaAZCHBoIExsCExwitkyDIrGNVi4+ES0EJjUdIxMDBBNUBKYcOIDEwgkssRsbIryigQCTADMAQCcuwDssgAcBwHHCUgHx1tMTJFMuwKykXC7cABmWwAsBIpIngIACF6o1FABSSICaIAcSQOEoUAgxA8HxWyEwaFAmAAnjhqugkSjYtYxliQAAVNglYy6UFNbLocQMBpNDwATTg1hqzNZihAAF8BTJMP9xBA0YoELlsXiCSBJQgGMYUDJ9DUilMPA4cPz0GoqgAKTVwA1wY3FFmUTnWKTaACMdvtAEpnYKpLL8TUPjRjFN+TIdXq5JaENauYptAAeAC8Dt2xwC7s98pwNCWmJkZEUbAYOCYONyIBt-IKCpocGMshqAGFczNFIWZMRMgx5VSaXS+dlhSnvejlaqQOr0CbtfZdTUzRaptPNVaS06na7kyBcV70IrBx4R5TqZku2CWiAgxrQzkAOQAZTYxArtgAquJ1Be8toANTaecIS9PuhwWRtCvEopggV9BTyXsQEqeU4FIGZjxbYw20ZcoQAAOSceUhxLNB7SeSIZAAEQUKBlFUdQagAGRWRBtBUCAWVXTCqhqJgOQjPDdgANmCEASKUFQ1AkGoAEk8BZExaOlAUy1FJBxUVGU1zlfspW3NVGRDLVAwnYM52KU0aCNb9w1tB1lzdWTZNSKBMgUZSYJqewPHXeUzQ8MUyHlbxfBgDxZHqJAzHJTVSlqelmlRCsqzPLUhQ9aCsJqJsVI3EBTHMbkZC8+VQnCTNoMMAlRTbGQAC8mjYNBSrgQogpC1BQDCtjIuPH1K2rdAOwPOpu0FKCnMJNhjBWVzVPQFZEgyDocoU7yajsqYyBWVLAuQRrmuKcK+qPaLOtretRULIUyyQewHLKUAVgrGZWuweoPGgeznNXG7pkxdBXA+QrntcFKIJkZBFAAa1Q5rSPI4SNBAKizAsSU7CWZDoe0NgPm0B8r0PBlxvSzLqhkD4c2lJrtJ2tr3RPcQJnkckPrZMmXLJv75RcomYq67TqmFEBCxZuz-vQVKOti9A-ymQDgMMntUlFNgQbgGt4XJJC2xqHMGHEatef6HNFYAdR8PwybVgktl1+XFYAeTiKA6H50AzbQAJKAEIUEohwSKJE9AAAU2DMTAIG0RGsZxqKRQmkAIBxBoRtREnQu21r+t56ZaYJUAGb1UBmdAVnXo5g7R0MqnHZjwX5RFzmaglgCgJAhzdZoSrVdbAlAl5n1jA6AWXuG0aA3LEuQDrLXjqpvWFbgI2-Pb5CCWiS39azkBna+sIsAgEGcSYReBtaHAxzJnvjFtpB7dxBf1dQe0V5ni+r4rjeAgSjBb0ZgurbgJ+HZvgk98PaJXkN7aG1F4ahxWEjEaDBUboyAree8EdjxuRqATROj0yYtXQLtXG6caZsDpmTHO5J86VwHiAdmI8xbc3LuSQuwt9q0JvHeU0mNnwiQforZWOAAEa3rDrOWq854mydh3NAFthGPztv-U2EjUCu3dsAr2ZEhKUX9oHBCUDIysOQXgyOaV5Sx3jrNBUSdsEp1wZTAhmd6YzC-lQhhVci40K5mOXmFdGF82YVzPR7C-xcNSK3NeG8u4c17s4yhEwh6+MOhPRsU8f6iP8vIg+qBl7SMVvwzeBUd57wPu-PMJ9QBnz-tfNJt975ZN-rIip4j0lv15jAT+ucY4-3KS-BRQDPZGI1sqQm5isFbRKKnPatiiFr1IUzKJQsnHF1oR4mQXiXFMIWX4pBATOGSE8ZEWZ1c4ni2fJLRuMsp4hJyeE8skT+5zJiWNdZ8SGwnRqSky53DQkKIylvYOu997qyKcfMup9fTnzqV09J1T2mr06Tk12FtmmtIYR08FOSenWSAA
Any help much appreciated!
What you're trying to do isn't logically possible. You have faceted on country. That means each country gets a line (working), a symbol (working) but how would it get a rule where the start point is one country and the end point is the other. One group does not know anything about the other group so you couldn't have a rule spanning the two countries.
If you want to keep your facet, you can do the following:
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "A basic line chart example.",
"width": 500,
"height": 200,
"padding": 5,
"signals": [],
"data": [
{
"name": "bombers",
"url": "https://gist.githubusercontent.com/vdvoorder/5b30997d8708dda783bb2b95d2e9ef34/raw/Bomber%2520Gap.csv",
"format": {
"type": "csv",
"parse": {"Total bombers": "number", "Year": "number"}
},
"transform": [
{
"type": "formula",
"as": "date",
"expr": "time(datetime(datum.Year, 1, 1))"
},
{"type": "filter", "expr": "datum.Year <= 1980"}
]
},
{
"name": "bombers2",
"source": "bombers",
"transform": [
{
"type": "pivot",
"field": "Country",
"value": "Total bombers",
"groupby": ["date"]
}
]
}
],
"scales": [
{
"name": "x",
"type": "time",
"range": "width",
"domain": {"data": "bombers", "field": "date"}
},
{
"name": "y",
"type": "linear",
"range": "height",
"nice": true,
"zero": true,
"domain": {"data": "bombers", "field": "Total bombers"}
},
{
"name": "color",
"type": "ordinal",
"range": "category",
"domain": {"data": "bombers", "field": "Country"}
}
],
"axes": [
{"orient": "bottom", "scale": "x"},
{"orient": "left", "scale": "y"}
],
"marks": [
{
"type": "group",
"from": {
"facet": {"name": "series", "data": "bombers", "groupby": "Country"}
},
"marks": [
{
"description": "Line for evolution of total bombers by country",
"type": "line",
"from": {"data": "series"},
"encode": {
"enter": {
"x": {"scale": "x", "field": "date"},
"y": {"scale": "y", "field": "Total bombers"},
"stroke": {"scale": "color", "field": "Country"},
"strokeCap": {"value": "round"},
"strokeWidth": {"value": 3},
"strokeOpacity": {"value": 0.5}
}
}
},
{
"description": "Points for total bombers by country",
"type": "symbol",
"from": {"data": "series"},
"encode": {
"enter": {
"x": {"scale": "x", "field": "date"},
"y": {"scale": "y", "field": "Total bombers"},
"size": {"value": 50},
"fill": {"scale": "color", "field": "Country"},
"strokeWidth": {"value": 20},
"stroke": {"value": "lightskyblue"}
},
"update": {
"fillOpacity": {"value": 1},
"strokeOpacity": {"value": 0}
},
"hover": {"strokeOpacity": {"value": 1}}
}
}
]
},
{
"description": "Rulers between country total bomber numbers",
"type": "rule",
"from": {"data": "bombers2"},
"encode": {
"update": {
"x": {"scale": "x", "field": "date"},
"y": {"scale": "y", "field": "Soviet Union"},
"y2": {"scale": "y", "field": "United States"},
"stroke": {"value": "lightskyblue"},
"strokeWidth": {"value": 3},
"strokeOpacity": {"value": 0.5}
}
}
}
]
}

How can I convert a list of dictionaries into a dictionary of lists in ansible?

It's kind of a challenge for me to use correct ansible filters.
Can someone help me with how I can convert a list of dictionaries?
This is my input data:
"_list_of_dict":
[
{
"groupid": "11",
"hostname": "host1.local",
"timeout": "5000",
"status": "ONLINE",
},
{
"groupid": "12",
"hostname": "host1.local",
"timeout": "5000",
"status": "ONLINE",
},
{
"groupid": "12",
"hostname": "host2.local",
"timeout": "5000",
"status": "ONLINE",
}
]
And this what I would like to get:
"_dict_of_list": {
"12": [
{
"hostname": "host2.local",
"timeout": "5000",
"status": "ONLINE",
},
{
"host": "host1.local",
"timeout": "5000",
"status": "ONLINE",
}
],
"11": [
{
"host": "host1.local",
"timeout": "5000",
"status": "ONLINE",
}
],
It might be that the list contains different numbers of groupid and each group could have different numbers of hosts and I have to combine them by groupid.
I found a solution myself.
That works for me.
Thanks, to everyone who tried to help I really appreciate it.
_dict_of_list: >-
{{ _dict_of_list | default({})
| combine({item.groupid: []
+ [{
'hostname': item.hostname,
'timeout': item. timeout,
'status': item. status
}]
+ _dict_of_list[item.groupid] | default([]) })
}}
with_items: "{{ _list_of_dict }}"

Egrep special expressions like \w in bracket expressions []

I am trying to use extended grep to extract data from a JSON. The regex I use is functional on my regexr instance, but for some reason it doesn't work in bash.
I tried many things, notably the bare double dash and various minor edits to the regex for escaping.
#!/bin/bash
networks='{ "networks": [ { "admin_state_up": true, "availability_zone_hints": [], "availability_zones": [], "created_at": "2019-03-12T23:45:13Z", "description": "", "id": "7188504a-72cb-4590-a9b0-414732017837", "ipv4_address_scope": null, "ipv6_address_scope": null, "is_default": false, "mtu": 1450, "name": "BLUE", "port_security_enabled": true, "project_id": "187d635aec4c43fe8e8918afb3a5c82e", "provider:network_type": "vxlan", "provider:physical_network": null, "provider:segmentation_id": 86, "revision_number": 2, "router:external": false, "shared": false, "status": "ACTIVE", "subnets": [], "tags": [], "tenant_id": "187d635aec4c43fe8e8918afb3a5c82e", "updated_at": "2019-03-12T23:45:13Z" }, { "admin_state_up": true, "availability_zone_hints": [], "availability_zones": [], "created_at": "2019-03-12T23:45:13Z", "description": "", "id": "ed82083f-0a7c-4322-a4fb-de8db23e2bae", "ipv4_address_scope": null, "ipv6_address_scope": null, "is_default": false, "mtu": 1450, "name": "RED", "port_security_enabled": true, "project_id": "187d635aec4c43fe8e8918afb3a5c82e", "provider:network_type": "vxlan", "provider:physical_network": null, "provider:segmentation_id": 108, "revision_number": 2, "router:external": false, "shared": false, "status": "ACTIVE", "subnets": [], "tags": [], "tenant_id": "187d635aec4c43fe8e8918afb3a5c82e", "updated_at": "2019-03-12T23:45:13Z" }, { "admin_state_up": true, "availability_zone_hints": [], "availability_zones": [], "created_at": "2019-03-12T23:45:13Z", "description": "", "id": "1eb6647e-869e-4e83-9468-43e2c320bccc", "ipv4_address_scope": null, "ipv6_address_scope": null, "is_default": false, "mtu": 1450, "name": "public", "port_security_enabled": true, "project_id": "187d635aec4c43fe8e8918afb3a5c82e", "provider:network_type": "vxlan", "provider:physical_network": null, "provider:segmentation_id": 32, "revision_number": 2, "router:external": false, "shared": false, "status": "ACTIVE", "subnets": [], "tags": [], "tenant_id": "187d635aec4c43fe8e8918afb3a5c82e", "updated_at": "2019-03-12T23:45:13Z" } ] }'
result=`echo $networks | grep -oE '"(id|name)": "([\w+-]+)"'`
echo $result
The aforementioned code doesn't work but if I switch to the following regex, it works. I just need to add extraction for id field too to be able to extract ids and names using \2 back reference (group 2)
grep -oE '"(id|name)": "(\w+)"'
Can you help me understand why the script doesn't work?
Full formatted JSON
{
"networks": [{
"admin_state_up": true,
"availability_zone_hints": [],
"availability_zones": [],
"created_at": "2019-03-12T23:45:13Z",
"description": "",
"id": "7188504a-72cb-4590-a9b0-414732017837",
"ipv4_address_scope": null,
"ipv6_address_scope": null,
"is_default": false,
"mtu": 1450,
"name": "BLUE",
"port_security_enabled": true,
"project_id": "187d635aec4c43fe8e8918afb3a5c82e",
"provider:network_type": "vxlan",
"provider:physical_network": null,
"provider:segmentation_id": 86,
"revision_number": 2,
"router:external": false,
"shared": false,
"status": "ACTIVE",
"subnets": [],
"tags": [],
"tenant_id": "187d635aec4c43fe8e8918afb3a5c82e",
"updated_at": "2019-03-12T23:45:13Z"
}, {
"admin_state_up": true,
"availability_zone_hints": [],
"availability_zones": [],
"created_at": "2019-03-12T23:45:13Z",
"description": "",
"id": "ed82083f-0a7c-4322-a4fb-de8db23e2bae",
"ipv4_address_scope": null,
"ipv6_address_scope": null,
"is_default": false,
"mtu": 1450,
"name": "RED",
"port_security_enabled": true,
"project_id": "187d635aec4c43fe8e8918afb3a5c82e",
"provider:network_type": "vxlan",
"provider:physical_network": null,
"provider:segmentation_id": 108,
"revision_number": 2,
"router:external": false,
"shared": false,
"status": "ACTIVE",
"subnets": [],
"tags": [],
"tenant_id": "187d635aec4c43fe8e8918afb3a5c82e",
"updated_at": "2019-03-12T23:45:13Z"
}, {
"admin_state_up": true,
"availability_zone_hints": [],
"availability_zones": [],
"created_at": "2019-03-12T23:45:13Z",
"description": "",
"id": "1eb6647e-869e-4e83-9468-43e2c320bccc",
"ipv4_address_scope": null,
"ipv6_address_scope": null,
"is_default": false,
"mtu": 1450,
"name": "public",
"port_security_enabled": true,
"project_id": "187d635aec4c43fe8e8918afb3a5c82e",
"provider:network_type": "vxlan",
"provider:physical_network": null,
"provider:segmentation_id": 32,
"revision_number": 2,
"router:external": false,
"shared": false,
"status": "ACTIVE",
"subnets": [],
"tags": [],
"tenant_id": "187d635aec4c43fe8e8918afb3a5c82e",
"updated_at": "2019-03-12T23:45:13Z"
}]
}
According to man grep:
The Backslash Character and Special Expressions
The symbol \w is a synonym for [[:alnum:]] and \W is a synonym for [^[:alnum:]]. ... A bracket expression is a list of characters enclosed by [ and ]. ... To include a literal ] place it first in the list. Similarly, to include a literal ^ place it anywhere but first. Finally, to include a literal - place it last.
Basically, \w is literally replaced by those characters when evaluated, giving you "([[[:alnum:]]+-]+)", which in a US standard locale gives you "([[a-zA-Z0-9]+-]+)".
Since a bracket expression is truncated by the first ] it sees (unless it is the first element of a bracket expression), the group is only [[[:alnum:]]+, or "1 or more of a digit, letter, and [. This expression is followed by -]+, meaning "exactly one hyphen and one or more ]". This is obviously pretty terrible.
If you try
echo $networks | grep -oE '"(id|name)": "([[:alnum:]+-]+)"'
I.e., \w without the outer bracket expression, the relevant part means "a group (surrounded by ") comprised of one or more digits, letters, hyphens, and plus signs", which outputs:
"id": "7188504a-72cb-4590-a9b0-414732017837"
"name": "BLUE"
"id": "ed82083f-0a7c-4322-a4fb-de8db23e2bae"
"name": "RED"
"id": "1eb6647e-869e-4e83-9468-43e2c320bccc"
"name": "public"
Using PERL (-P) instead of Extended (-E) regexp, looks like the \w is interpreted as expected, without escaping issue: note the -oP
result=$( echo $networks | grep -oP '"(id|name)": "([\w+-]+)"' ) ;
echo $result
"id": "7188504a-72cb-4590-a9b0-414732017837" "name": "BLUE" "id": "ed82083f-0a7c-4322-a4fb-de8db23e2bae" "name": "RED" "id": "1eb6647e-869e-4e83-9468-43e2c320bccc" "name": "public"
As a workaround (it does not resolve the "escaping \w issue)
result=$( echo $networks | grep -oE '"(id|name)": "([a-zA-Z_+-]+)"' ) ;
echo $result
Prints me:
"name": "BLUE" "name": "RED" "name": "public"
Note: prefer using $( ) syntax to execute sub shells rather than the backtick.

Remove whitespace after +44 and quotation marks around lat/long in JSON string with regex

In the example snippet below I have some JSON which needs to be edited (over 1400 entries). I need to achieve 2 things:
In this example line: "phone": "+44 2079693900", I need to remove the whitespace between +44 and 2079693900 but for all records. Resulting in: "+442079693900"
For latitude and longitude I need to get rid of the double quotes around the numbers, as the API I am using only accepts these values as floats.
Example: "latitude": "51.51736", needs to be: "latitude": 51.51736
I am most familiar with Ruby, and have done some parsing of JSON with this in the past, but I thought Regex would be the best tool to use for this kind of basic data cleaning task. I have referred to regex101.com and regular-expressions.info but I'm pretty stuck at this point. Thanks in advance!
[
{
"id": "101756",
"name": "1 Lombard Street
"email": "reception#1lombardstreet.com",
"website": "http://www.1lombardstreet.com",
"location": {
"latitude": "51.5129",
"longitude": "-0.089",
"address": {
"line1": "1 Lombard Street",
"line2": "",
"line3": "",
"postcode": "EC3V 9AA",
"city": "London",
"country": "UK"
}
}
},
{
"id": "105371",
"name": "108 Brasserie",
"phone": "+44 2079693900",
"email": "enquiries#108marylebonelane.com",
"website": "http://www.108brasserie.com",
"location": {
"latitude": "51.51795",
"longitude": "-0.15079",
"address": {
"line1": "108 Marylebone Lane",
"line2": "",
"line3": "",
"postcode": "W1U 2QE",
"city": "London",
"country": "UK"
}
}
},
{
"id": "108701",
"name": "1901 Restaurant",
"phone": "+44 2076187000",
"email": "london.restres#andaz.com",
"website": "http://www.andazdining.com",
"location": {
"latitude": "51.51736",
"longitude": "-0.08123",
"address": {
"line1": "Andaz Hotel",
"line2": "40 Liverpool Street",
"line3": "",
"postcode": "EC2M 7QN",
"city": "London",
"country": "UK"
}
}
},
{
"id": "102190",
"name": "2 Bridge Place",
"phone": "+44 2078028555",
"email": "fb#dtlondonvictoria.com",
"website": "http://crimsonhotels.comdoubletreelondonvictoriadiningpre-theatre-dining",
"location": {
"latitude": "51.49396",
"longitude": "-0.14343",
"address": {
"line1": "2 Bridge Place",
"line2": "Victoria",
"line3": "",
"postcode": "SW1V 1QA",
"city": "London",
"country": "UK"
}
}
},
{
"id": "102063",
"name": "2 Veneti",
"phone": "+44 2076370789",
"email": "2veneti#btconnect.com",
"website": "http://www.2veneti.com",
"location": {
"latitude": "51.5168",
"longitude": "-0.14673",
"address": {
"line1": "10 Wigmore Street",
"line2": "",
"line3": "",
"postcode": "W1U 2RD",
"city": "London",
"country": "UK"
}
}
},
You can use the following regex:
("phone":\s*"\+44)\s+|("(?:latitude|longitude)":\s*)"([^"]+)"
With the following replacement:
$1$2$3
The idea is to capture what we want and not capture what we do not, and then use backreferences to restore the substrings we want to keep.
Regex explanation:
The pattern contains 2 alternatives joined with | alternation operator:
("phone":\s*"\+44)\s+:
("phone":\s*"\+44) - the 1st capturing group matching literal "phone": + optional whitespace, then +44 literally
\s+ - 1 or more whitespaces that we'll remove
("(?:latitude|longitude)":\s*)"([^"]+)":
("(?:latitude|longitude)":\s*) - the second capturing group matching "latitude": or "longitude": and 0 or more whitespace characters
" - Literal " that we'll drop
([^"]+) - the third capturing group matching 1 or more characters other than " (we'll keep that)
" - again, a literal " that we'll drop.
See demo

column chart issue with google-chart api

I want to show column chart with google chart api and here is my code.
I want to show Month name in bottom x-axis and value to y-axis at left side of graph vetically,however i'm not able to get it
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(drawChart);
function drawVisualization() {
// Create and populate the data table.
var JSONObject = { "cols": [
{ "id": "", "label": "Jan", "Pattern": "", "type": "number" },
{ "id": "", "label": "Feb", "Pattern": "", "type": "number" },
{ "id": "", "label": "Mar", "Pattern": "", "type": "number" },
{ "id": "", "label": "Apr", "Pattern": "", "type": "number" },
{ "id": "", "label": "May", "Pattern": "", "type": "number" },
{ "id": "", "label": "Jun", "Pattern": "", "type": "number" },
{ "id": "", "label": "Jul", "Pattern": "", "type": "number" },
{ "id": "", "label": "Aug", "Pattern": "", "type": "number" },
{ "id": "", "label": "Sep", "Pattern": "", "type": "number" },
{ "id": "", "label": "Oct", "Pattern": "", "type": "number" },
{ "id": "", "label": "Nov", "Pattern": "", "type": "number" },
{ "id": "", "label": "Dec", "Pattern": "", "type": "number" }
], "rows":
[{ "c": [
{ "v": "0"},
{ "v": "0", "f": null },
{ "v": "0", "f": null },
{ "v": "0", "f": null },
{ "v": "0", "f": null },
{ "v": "0", "f": null },
{ "v": "2000", "f": null },
{ "v": "0", "f": null },
{ "v": "0", "f": null },
{ "v": "1000", "f": null },
{ "v": "0", "f": null },
{ "v": "0", "f": null }
]
}]
};
var data = new google.visualization.DataTable(JSONObject);
// Create and draw the visualization.
new google.visualization.ColumnChart(document.getElementById('visualization')).
draw(data,
{title:"Yearly Coffee Consumption by Country",
width:600, height:400,
hAxis: {title: "Year"}}
);
}
​
You need to change the layout of your data. The Visualization API ColumnCharts (and most similar Viz API charts) expect data with the domain axis (x-axis for ColumnCharts) values in the first column and the values for each data series in the following columns (where each column is one series of data). Given your requirements and your existing data, I think you want a DataTable with two columns of data: "month" and "value" (or whatever you decide to call it). Here's an example of what it might look like:
var JSONObject = {
"cols": [
{"type": "string", "label": "Month"},
{"type": "number", "label": "Value"}
],
"rows": [
{"c":[{"v": "Jan"}, {"v": 0}]},
{"c":[{"v": "Feb"}, {"v": 0}]},
{"c":[{"v": "Mar"}, {"v": 0}]},
{"c":[{"v": "Apr"}, {"v": 0}]},
{"c":[{"v": "May"}, {"v": 0}]},
{"c":[{"v": "Jun"}, {"v": 0}]},
{"c":[{"v": "Jul"}, {"v": 2000}]},
{"c":[{"v": "Aug"}, {"v": 0}]},
{"c":[{"v": "Sep"}, {"v": 0}]},
{"c":[{"v": "Oct"}, {"v": 1000}]},
{"c":[{"v": "Nov"}, {"v": 0}]},
{"c":[{"v": "Dec"}, {"v": 0}]}
]
};