[英]Regular expression to find a string that begins with > and ends with }
我可以知道如何編寫正則表達式來獲取以>
開頭和以}
結尾的字符串嗎?
示例字符串 :
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中,必須轉義}
。 通過@TJ Crowder轉換正確的答案,得到:
FIND ALL OCCURRENCES OF REGEX '>[^}]+\}' IN 'data>/ab/cd/peter} ;gopal came prop>/site/sing/perl};' RESULTS DATA(results).
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.