我可以知道如何编写正则表达式来获取以>
开头并以}
结尾的字符串吗?
示例字符串:
data>/ab/cd/peter} ;gopal came prop>/site/sing/perl};
我想要以下子字符串:
>/ab/cd/peter}
>site/sing/perl}
我试过这个,但不知道如何从>
开始我的发现的条件:
(\/(\w+)\/)*(\w+)(@*)(\w+)(~*)((\w+)?)\/(\w+)\}
它只是/>[^}]+}/g
:>
标记从哪里开始,[^}]+
说“任何不是}
”一次或多次,}
标记在哪里停止:
const str = "data>/ab/cd/peter} ;gopal came prop>/site/sing/perl};";
const rex = />[^}]+}/g;
let match;
while (!!(match = rex.exec(str))) {
console.log(match[0]);
}
试试这个javascript的正则表达式:
var inputStr = "data>/ab/cd/peter} ;gopal came prop>/site/sing/perl};";
var outputStr = inputStr.match(/(\>)([^\>\}]*)(\})/g);
console.log(outputStr);
在ABAP中,你必须逃离}
。转换@ T.J的正确答案。克劳德,这给了:
FIND ALL OCCURRENCES OF REGEX '>[^}]+\}' IN 'data>/ab/cd/peter} ;gopal came prop>/site/sing/perl};' RESULTS DATA(results).