英文:
Get all Content thats between Square Brackets: Regex
问题
"parameters('ECC_Shipment_Trigger_properties_pl_ecc_shipment_adls_sql_parameters_File_system')"
英文:
I have the follwing string:
"[parameters('ECC_Shipment_Trigger_properties_pl_ecc_shipment_adls_sql_parameters_File_system')]"
and I would like to write a regular expression that return only:
parameters('ECC_Shipment_Trigger_properties_pl_ecc_shipment_adls_sql_parameters_File_system')
Keeping in mind that I only need content that starts as:
parameters('some string')
So far I have come up with (?<=[parameters(').+?(?=')) which only returns the text between single quotes.
for testing, I am using https://regexr.com/
How can I modify my current regex to get this result?
答案1
得分: 1
正向后瞻是一种断言(不消耗字符),因此这部分 (?<=\[parameters\(') 表示从当前位置开始断言左侧是 [parameters(。
如果不使用前瞻后顾,可以使用捕获组和一个匹配任何字符但不包括 ' 的否定字符类。
值在第一个捕获组中:
[(parameters('[^']+'))]
如果想要使用前瞻后顾,这可能是一个选项,断言左侧是 [,右侧是 ]:
(?<=[)parameters('[^']+')(?=])
英文:
The positive lookbehind is an assertion (non consuming), so this part (?<=\[parameters\(') means that from the current position it asserts what is on the left is [parameters(.
Instead of a lookaround, you could use a capturing group and a negated character class matching any char except a ' instead.
The value is in the first capturing group.
\[(parameters\('[^']+'\))\]
If you want to use lookaround, this might be an option, asserting what is on the left is [ and what is on the right is ]
(?<=\[)parameters\('[^']+'\)(?=\])
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论