简体   繁体   中英

Get strings inside four brackets (regex)

How i can write something like this:

var s = "[hello world](one two)";
var x = s.replace(REGEX, '<p>$1</p><b>$2</b>');

output:

<p>hello world</p><b>one two</b>

\n
\n
\n
console.log( "[hello world](one two)".replace(/\\[(.*)\\]\\((.*)\\)/, '<p>$1</p><b>$2</b>'));
\n
\n
\n

Use the following regex with negated character class .

 var s = "[hello world](one two)"; var x = s.replace(/\\[([^\\]]*)]\\(([^)]*)\\)/, '<p>$1</p><b>$2</b>'); console.log(x); 

Regex explanation here.

使用带有regex.exec(string)和this(([。 ])|((。 )))+(或类似于此的东西)的捕获组并构建theputut字符串

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM