[英]regular expression , get text between two symbols
Trying to get text between two symbols. 试图在两个符号之间获取文本。 Regex too tough for me.
正则表达式对我来说太难了。 Here is the string
这是字符串
" Hello my {{name}} , I'm from /# singapore {{city}} #/". I text between "/# - #/"
Here how I tried , but it doesnt work \\#[\\w]+\\#
. 这是我尝试的方式,但是
\\#[\\w]+\\#
不起作用。 What I'm missing? 我想念的是什么?
Try following pattern: \\/#(.+)#\\/
尝试以下模式:
\\/#(.+)#\\/
Explanation: 说明:
\\/#
- match /#
literally \\/#
-按字面匹配/#
(.+)
- match one or more of any characters and store it inside capturing group (.+)
-匹配任意一个或多个字符并将其存储在捕获组中
#\\/
= match #/
literally #\\/
=匹配#/
var txt = "Hello my {{name}} , I'm from /# singapore {{city}} #/ adasdwq"; var match = txt.match("\\/#(.+)#\\/"); console.log(match);
You can use split and join 您可以使用拆分和合并
var a='/#name#/'; console.log(a.split('/#').join('').split('#/').join(''))
Try 尝试
const text = 'xxxx #needIt# xxxx'; const needText = text.match(/(?<=\\#).*(?=\\#)/)[0]; console.log(needText)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.