英文:
How to modify a regular expression to search between a special string and a character?
问题
我正在尝试编写一个正则表达式来搜索特定字符串和字符之间的内容。
我有一个正则表达式:
b(\(.*?)\)
它用于查找在 "b(" 和 ")" 之间的匹配项,例如:
字符串:az[b('0x611', '0*L3')]
匹配:b('0x611', '0*L3')
但有时会出现这样的行:
字符串:(G, f[b('0x4ed', 'S)Oi')])
在这种情况下,匹配项将是:b('0x4ed', 'S)
, 这是错误的。
我尝试通过查找在 "b('0x4ed', 'S))" 和 ")" 之间的匹配项来解决这个问题,但当我尝试将正则表达式改成如下形式 b('0x4ed', 'S)(.*?)\)
, 它就不起作用了。
我该如何解决这个问题?
英文:
I'm trying to write a regular expression to search between a special string and a character.
I have a regular expression:
b(\(.*?)\)
It looks for matches between "b(" and ")", for example:
String: az[b('0x611', '0*L3')]
Match: b('0x611', '0*L3')
But sometimes there are lines like this:
String: (G, f[b('0x4ed', 'S)Oi')])
And in this case match will be: b('0x4ed', 'S)
, and that wrong.
I'm trying to solve this by looking for matches between "b('0x4ed', 'S)" and ")", but when I try to bring the regular expression to the following form b('0x4ed', 'S)(\(.*?)\)
, it stops working.
How could I get out of this situation?
答案1
得分: 1
Use: "not one or more singlequotes until a singlequote" like: '[^']+'
Example
b\('[^']+', ?'[^']+'\)
PS: if the value can be empty ''
use zero-or-more *
:
b\('[^']+', ?'[^']*'\)
英文:
Use: "not one or more singlequotes until a singlequote" like: '[^']+'
Example
b\('[^']+', ?'[^']+'\)
PS: if the value can be empty ''
use zero-or-more *
:
b\('[^']+', ?'[^']*'\)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论