Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
150 views
in Technique[技术] by (71.8m points)

js 获取一行代码中的所有中文块并获取下标?

str = '<div>12344我是</div><div>第 三方dsfsdff</div>'

需要提取出来 [我是,第 三方]
所对应的下标 11,24


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
'<div>12344我是</div><div>第三方dsfsdff</div>'.replace(/[u4e00-u9fa5]+/g, function($match, $pos){
    console.log($match, $pos);
    return $match;
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...