简体   繁体   English

正则表达式在特定单词后获取文本?

[英]Regex to get text after a specific word?

How to get text inside quote("asd") after value -> "name": like: 如何在value-> "name":之后的quote(“ asd”)中获取文本"name": like:

"name":"John","name":"1-John", "name":"123", "name":"123","name":"A0-0s".

I need to get all inside quote(""): 我需要获取所有内部quote(“”):

John
1-John
123
A0-0s

You can use the following regex with lookbehind: 您可以将以下正则表达式与lookbehind一起使用:

(?<="name":")[^"]+

Demo: https://regex101.com/r/TfkNXE/1 演示: https : //regex101.com/r/TfkNXE/1

You can use the following regex 您可以使用以下正则表达式

[\w-]+(?=")

Demo at regex 101 regex 101上的演示

The regular expression you can use is: \\"name\\":\\"([a-zA-Z0-9--])+\\" . 您可以使用的正则表达式为: \\"name\\":\\"([a-zA-Z0-9--])+\\" Due to the brackets '()' the required result will be present in the first group of the regex match. 由于方括号(()),所需结果将出现在正则表达式匹配的第一组中。

However in case you have multiple combinations in a single string like the one you had in the example, remember to use find() or search() method and read more about search and match methods . 但是,如果您在单个字符串中有多个组合(例如您在示例中使用的组合),请记住使用find()或search()方法, 并详细了解search和match方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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