[英]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>.*?)"
将匹配所有结果,然后您应该能够遍历匹配以分别处理每个结果。
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.