简体   繁体   English

使用正则表达式提取第 2、3、4 等匹配项

[英]Extract 2nd, 3rd, 4th, etc matches using Regex

:) :)

I am a very noob regex user and I am trying to extract the content of every line, exactly the content of ingredient-data , which will be wheat flour for first line, white sugar for the second, and so on.我是一个非常菜鸟的正则表达式用户,我正在尝试提取每一行的内容,确切地说是ingredient-data的内容,第一行是wheat flour ,第二行是white sugar ,依此类推。

I usually extract stuff using (.*?) but this matches all the results and I need different regex to match all of them separately to extract all of the results by separate.我通常使用 (.*?) 提取内容,但这匹配所有结果,我需要不同的正则表达式来分别匹配所有这些以单独提取所有结果。

Thanks <3谢谢 <3

<ul>
  <li ingredient-data="wheat flour">1 cup wheat flour</li>
  <li ingredient-data="white sugar">3 tablespoons white sugar</li>
  <li ingredient-data="baking powder">2 teaspoons baking powder</li>
  <li ingredient-data="baking soda">½ teaspoon baking soda</li>
  <li ingredient-data="salt">½ teaspoon salt</li>
</ul>

You should have some success with what you're already using if you can match what you need already.如果你能匹配你已经需要的东西,你应该在你已经使用的东西上取得一些成功。

For example the regex ingredient-data="(?P<ingredient>.*?)" will match all the results, and then you should be able to iterate through the matches to process each result separatly.例如,正则表达式ingredient-data="(?P<ingredient>.*?)"将匹配所有结果,然后您应该能够遍历匹配以分别处理每个结果。

正则表达式 101 输出

If that's not exactly what you're asking, could you provide a little more context and some code?如果这不是您要问的,您能否提供更多上下文和一些代码?

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

相关问题 正则表达式提取第二和第三个字符串 - Regex to extract 2nd and 3rd string 在序号字符串(第二,第八,第三,第一等)上分割地址字符串 - Splitting address strings on Sequential-Number strings (2nd, 8th, 3rd, first, etc..) 正则表达式在 Google 表格中提取 IP 地址(第 3 和第 4 八位字节)的最后两个八位字节 - Regex to extract last two octets of IP address (3rd and 4th Octet) in Google Sheets 如何使用正则表达式查找和替换字符串中第二个逗号和第四个逗号之间的任何字符 - How to find and replace any characters between 2nd comma and 4th comma in a string using regex 提取第二个下划线和第三个下划线或空格之间的单词 - extract word between 2nd underscore and 3rd underscore or space 在第2个和第3个逗号之间提取单词 - Extract words between the 2nd and the 3rd comma 正则表达式获取管道之间的第二和第三变量 - RegEx to get 2nd and 3rd variables between pipes Python正则表达式匹配行中的第二个或第三个单词 - Python Regex match 2nd or 3rd word in line 我需要 oracle 正则表达式将第 2 到第 4 个 position 个字符替换为符号 - I need oracle regex to replace 2nd to 4th position characters to symbol 搜索模式,在该行上使用 sed 仅更改文件的第 3 列和第 4 列 - search for a pattern , change just the 3rd and 4th columns of a file using sed on that line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM