正则表达式,用于查找以>开头并以}结尾的字符串

问题描述 投票:-1回答:3

我可以知道如何编写正则表达式来获取以>开头并以}结尾的字符串吗?

示例字符串:

data>/ab/cd/peter} ;gopal came prop>/site/sing/perl};

我想要以下子字符串:

>/ab/cd/peter}
>site/sing/perl}

我试过这个,但不知道如何从>开始我的发现的条件:

(\/(\w+)\/)*(\w+)(@*)(\w+)(~*)((\w+)?)\/(\w+)\}
javascript php regex perl abap
3个回答
3
投票

它只是/>[^}]+}/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]);
}

0
投票

试试这个javascript的正则表达式:

var inputStr = "data>/ab/cd/peter} ;gopal came prop>/site/sing/perl};";

var outputStr = inputStr.match(/(\>)([^\>\}]*)(\})/g);
console.log(outputStr);

0
投票

在ABAP中,你必须逃离}。转换@ T.J的正确答案。克劳德,这给了:

FIND ALL OCCURRENCES OF REGEX '>[^}]+\}' IN 'data>/ab/cd/peter} ;gopal came prop>/site/sing/perl};' RESULTS DATA(results). 
© www.soinside.com 2019 - 2024. All rights reserved.