我有这样的文字:
"headword":"final"
"headword":"family name"
"headword":"penultimate"
我想只获得
final
family name
penultimate
我尝试了几个正则表达式,但没有运气使它工作, 这将做相反的事情
(\W*(headword))\W*
我试图否定使用[^]不起作用
答案 0 :(得分:0)
使用以下正则表达式模式:
(?:"\w+":)"([^"]+)"
https://regex101.com/r/KLPP22/1
[^"]+
- 匹配除"
所需的值位于 1st Capturing Group
中答案 1 :(得分:0)
答案 2 :(得分:0)
// str is the text you want to replace and first captured group is replaced with whole capture.
str.replace(/(?:"headword":")([^"]+)(?:")/gmi, '$1');