用于解析JSON的正则表达式 [英] Regex for Parsing JSON
问题描述
我有一列数据是我直接从Redshift在Tableau中读取的.该列包含一个JSON对象.看起来像这样:
I have a column of data I'm reading in Tableau directly from Redshift. This column contains a JSON object. It looks like this:
{"Age": 58, "City": "Wisconsin Rapids", "Race": "Other", "State": "Wisconsin", "Gender": "Female", "Country": "United States"}
我希望通过使用Tableau的REGEXP_EXTRACT函数为每个关注的数据点生成一个具有计算字段的列来提取此数据. IE.年龄列,城市列等.
I wish to extract this data by generating a column with a calculated field for each data point of interest using Tableau's REGEXP_EXTRACT function. I.e. an Age column, a City column etc.
我如何编写一行正则表达式以获取Age的值58,Wisoncsin Rapids的City等值.
How do I write a line of regular expressions to get the value of 58 for Age, Wisoncsin Rapids for City, etc.
谢谢!
推荐答案
您可以使用此正则表达式:
You can use this regex :
"Age"\s?+:\s?+"?([[:alnum:]\s]+)"?
提取其值,例如Age
to extract its value here Age for example
如果您想要其他键,例如州",请使用州"而不是年龄"
if you want other key for example State use State instead of Age
"State"\s?+:\s?+"?([[:alnum:]\s]+)"?
您将在第一组中找到键的值 在这里看到 https://regex101.com/r/KA7PSl/2
you'll find the value of the key in the first group See here https://regex101.com/r/KA7PSl/2
这篇关于用于解析JSON的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!