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
3.6k views
in Technique[技术] by (71.8m points)

如何通过正则获取字符串中匹配的字符

如何通过正则匹配出所有的name的value值

const str = '[{"id":"1","name":"t1","children":[{"id":"1","name":"t1-1","children":[]}]},{"id":"1","name":"t2","children":[]}]';
str.match(...)

想要的结果(Array): ['t1', 't1-1',t2]


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

1 Answer

0 votes
by (71.8m points)

后行断言:/(?<="name":")([^"])+/g

image.png


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

...