选择从第一个“ {”到最后一个“}”的所有内容

时间:2019-06-20 19:03:38

标签: regex

我正在尝试创建一个正则表达式,以从该字符串中提取第一个}和最后一个from pydap.client import open_url from pydap.cas.urs import setup_session import xarray as xr dataset_url = 'https://opendap.cr.usgs.gov/opendap/hyrax/MOD13Q1.006/h00v08.ncml.nc4' ### Replace with your username and password session = setup_session('XXXX', 'XXXXXX', check_url=dataset_url) store = xr.backends.PydapDataStore.open(dataset_url, session=session) ds = xr.open_dataset(store) --------------------------------------------------------------------------- HTTPError Traceback (most recent call last) <ipython-input-5-0ddf552f3174> in <module> ----> 1 store = xr.backends.PydapDataStore.open(dataset_url, session=session) 2 ds = xr.open_dataset(store) /opt/conda/lib/python3.7/site-packages/xarray/backends/pydap_.py in open(cls, url, session) 71 def open(cls, url, session=None): 72 import pydap.client ---> 73 ds = pydap.client.open_url(url, session=session) 74 return cls(ds) 75 /opt/conda/lib/python3.7/site-packages/pydap/client.py in open_url(url, application, session, output_grid, timeout) 65 """ 66 dataset = DAPHandler(url, application, session, output_grid, ---> 67 timeout).dataset 68 69 # attach server-side functions /opt/conda/lib/python3.7/site-packages/pydap/handlers/dap.py in __init__(self, url, application, session, output_grid, timeout) 52 ddsurl = urlunsplit((scheme, netloc, path + '.dds', query, fragment)) 53 r = GET(ddsurl, application, session, timeout=timeout) ---> 54 raise_for_status(r) 55 if not r.charset: 56 r.charset = 'ascii' /opt/conda/lib/python3.7/site-packages/pydap/net.py in raise_for_status(response) 37 detail=response.status+'\n'+response.text, 38 headers=response.headers, ---> 39 comment=response.body 40 ) 41 HTTPError: 404 Not Found <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <link rel='stylesheet' href='/opendap/docs/css/contents.css' type='text/css'/> <title>Hyrax: Resource Not Found</title> </head> <body> <p align="left">&nbsp;</p> <h1 align="center">Hyrax - Resource Not Found (404) </h1> <hr align="left" size="1" noshade="noshade"/> <table width="100%" border="0"> <tr> <td> <a href="/opendap/docs/images/largeEarth.jpg"> <img src="/opendap/docs/images/smallEarth.jpg" alt="I looked everywhere!" title="I looked everywhere!" border="0"/> </a> </td> <td> <p align="left">The URL requested does not describe a resource that can be found on this server.</p> <p align="left">If you would like to start at the top level of this server, go <a href="/opendap/"><strong>HERE</strong></a>.</p> <p align="left">The specific error message associated with your request was:</p> <blockquote> <p><strong>Failed to locate resource: /MOD13Q1.006/h00v08.ncml.nc4.dds </strong></p> </blockquote> <p align="left">If you think that the server is broken (that the URL you submitted should have worked), then please contact the OPeNDAP user support coordinator at: <a href="mailto:lpdaac@usgs.gov">lpdaac@usgs.gov</a> </p> </td> </tr> </table> <hr align="left" size="1" noshade="noshade"/> <h1 align="center">Hyrax - Resource Not Found (404) </h1> </body> </html> 之间的字符串:

  

@ base64Binary3http://schemas.microsoft.com/2003/10/Serialization/��{“ topic”:“ /subscriptions/xx/resourceGroups/usap-devgru-BBB-interfaces-resgrp/providers/Microsoft.Storage / storageAccounts / BBBdgdevstor“,” subject“:” / blobServices / default / containers / coloradoAAAready / blobs / SIU-S13_2019-5-29   16.26.11_27319.HL7“,” eventType“:” Microsoft.Storage.BlobCreated“,” eventTime“:” 2019-06-20T17:10:20.5025763Z“,” id“:” ab0f7xxxxxxx08b-278fa906f76d“,”数据“: {“ api”:“ PutBlockList”,“ clientRequestId”:“ xxxx6-92a6-7a87xx2be32b”,“ requestId”:“ xxxxx0000”,“ eTag”:“ 0xxxxxD2AEC9”,“ contentType”:“应用程序/八位字节流”,“ contentLength“:1368,” blobType“:” BlockBlob“,” url“:” https://BBBdgdevstor.blob.core.windows.net/coloradoAAAready/SIU-S13_2019-5-29   16.26.11_27319.HL7“,” sequencer“:” 0000000000000000000000000000019C0000000000969f41“,” storageDiagnostics“:{” batchId“:” a01x7f5-0785x256“}},” dataVersion“:”“,” metadataVersion“:” 1“}

结果字符串为:

  

{“主题”:” / subscriptions / xx / resourceGroups / usap-devgru-BBB-interfaces-resgrp / providers / Microsoft.Storage / storageAccounts / BBBdgdevstor”,“主题”:“ / blobServices / default / containers / coloradoAAAready / blobs / SIU-S13_2019-5-29   16.26.11_27319.HL7“,” eventType“:” Microsoft.Storage.BlobCreated“,” eventTime“:” 2019-06-20T17:10:20.5025763Z“,” id“:” ab0f7xxxxxxx08b-278fa906f76d“,”数据“: {“ api”:“ PutBlockList”,“ clientRequestId”:“ xxxx6-92a6-7a87xx2be32b”,“ requestId”:“ xxxxx0000”,“ eTag”:“ 0xxxxxD2AEC9”,“ contentType”:“应用程序/八位字节流”,“ contentLength“:1368,” blobType“:” BlockBlob“,” url“:” https://BBBdgdevstor.blob.core.windows.net/coloradoAAAready/SIU-S13_2019-5-29   16.26.11_27319.HL7“,” sequencer“:” 0000000000000000000000000000019C0000000000969f41“,” storageDiagnostics“:{” batchId“:” a01x7f5-0785x256“}},” dataVersion“:”“,” metadataVersion“:” 1“}

如何选择第一个“ {”到最后一个“}”中的文本?

1 个答案:

答案 0 :(得分:1)

这个正则表达式不会帮您吗?

{.*}

默认情况下,正则表达式天生就是贪婪的,因此它将搜索满足条件的最大匹配,这听起来像您想要的。