c# - 如何在字符串中搜索文本并抓取搜索文本之后的所有内容,直到它到达一个字符?
问题描述
我正在网络上搜索一个巨大的 html 文档,其中包含多个名称实例。整个页面源代码的每个部分都将包含类似这样的内容
{"keyword_text":"kathy smith","item_logging_id":"2021-05-16:yakMrD","item_logging_info":"{"source":"entity_bootstrap_connected_user_suggestion",{"keyword_text":"courtney lee","item_logging_id ":"2021-05-16:lX1LC2","item_logging_info":"{"source":"entity_bootstrap_connected_user_suggestion",
我想获取源中的所有名称并将它们放入文本框中。
在字符串中搜索 "keyword_text":" 然后抓取所有文本,直到它到达 " 不包括 "
我希望最终结果是
kathy smith
courtney lee
解决方案
Considering the "until it reaches the character" you can use the regex ([^\"]*)
^
means NOT and *
means multiple times. So it reads everything until the first appearance of "
. The \
is to escape the quotes.
So in your case this is the regex:
\"keyword_text\":\"([^\"]*)
to get the name-part without quotes.
And in c# context:
var matches= new Regex("\"keyword_text\":\"([^\"]*)").Matches(yourInputText);
foreach (Match match in matches)
{
Console.WriteLine(match.Groups[1].Value);
}
推荐阅读
- oracle-apex - 如何在 apex 中导出图表?
- excel - VBA Selecting Array Values Between Specified Values
- javascript - Display radio button with object values in map javascript
- java - How to check a condition at all time during java form is running?
- oracle - 即使我在“项目数据源”(DataGrip 中的 crtl+alt+shift+S 中的 crtl+alt+shift+S)中检查以记住它,我也必须使用 oracle 输入传递 datagrip 中的每个操作
- numpy - 如何使numpy数组切片元素不同?
- logging - InvalidOperationException - 无法构造类型 LogWriter。您必须配置容器以提供此值
- typo3 - 设置 realurl 以防止“Bad 'L' parameter”错误
- reactjs - React - 定期获取数据(Webrequests)
- php - MySQLi 到 SQLSRV 的迁移 - MySQLi 的 fetch_assoc() 与 SQLSRV 的 fetch()