nic*_*ch3 12 regex google-sheets
我的文本字符串在单元格D2中:
Decision, ERC Case No. 2009-094 MC, In the Matter of the Application for Authority to Secure Loan from the National Electrification Administration (NEA), with Prayer for Issuance of Provisional Authority, Dinagat Island Electric Cooperative, Inc. (DIELCO) applicant(12/29/2011)
Run Code Online (Sandbox Code Playgroud)
这个功能:
=regexextract(D2,"\([A-Z]*\)")
Run Code Online (Sandbox Code Playgroud)
会抓住(NEA)而不是(DIELCO)
我想提取(NEA)和(DIELCO)
Met*_*aEd 14
您可以使用捕获组,这将导致regexextract()返回一个数组.您可以将其用作单元格结果,在这种情况下,您将获得一系列结果,或者您可以将数组提供给另一个函数以将其重新格式化为您的目的.例如:
regexextract( "abracadabra" ; "(bra).*(bra)" )
Run Code Online (Sandbox Code Playgroud)
将返回数组:
{bra,bra}
Run Code Online (Sandbox Code Playgroud)
另一种方法是使用regexreplace().这样做的优点是替换是全局的(如s/pattern/replacement/g),因此您无需事先知道结果的数量.例如:
regexreplace( "aBRAcadaBRA" ; "[a-z]+" ; "..." )
Run Code Online (Sandbox Code Playgroud)
将返回字符串:
...BRA...BRA
Run Code Online (Sandbox Code Playgroud)