英文:
regex (convert br and dash to li, or find dash between br tag)
问题
如何将“-”转换为 PHP 中的列表(li)?示例 HTML:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
任何文本 - 任何文本 任何文本 任何文本 任何文本 任何文本
<br><br>- 任何文本 任何文本<br>- 任何文本 1 2 3 | \ ,<br><br>
<br>任何文本
<!-- end snippet -->
我尝试使用以下正则表达式:
(<\s*[^>]*>-\s?(.*?)<\s*[^>]*>)
但只能找到第一个匹配项...
通过这个正则表达式可以找到我需要的一切 - 从<br>
标签开始,但它无法设置搜索的结束(结束标记将在<br>
标签中):
<br>\s?-\s?(.*?)
(链接到测试: https://regex101.com/r/CqjpzX/1)。
英文:
How can convert the "-" to list (li) on PHP? Example HTML:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
any text - any text any text any text any text any text
<br><br>- any text any text<br>- any text 1 2 3 | \ ,<br><br>
<br>any text
<!-- end snippet -->
I tried using the following regex:
(<\s*[^>]*>-\s?(.*?)<\s*[^>]*>)
But then only the first match can be found...
By this can find everything what I need - that start from the <br>
tag, but it cannot set the end of the search (it will be in the <br>
tag):
<br>\s?-\s?(.*?)
(link to test: https://regex101.com/r/CqjpzX/1 ).
答案1
得分: 0
I'm not 100% sure this is what you're asking for, but if you want to capture everything between the <br>-
and <br>
you need to use a regex like this.
<br>\s?-\s?(.*?)(?=<br>)
Here is an example on your text https://regex101.com/r/71cHQB/1
I hope this can help you.
Also don't forget the /g after the regex so it doesn't stop after the first match.
英文:
I'm not 100% sure this is what you're asking for, but if you want to capture everything between the <br>-
and <br>
you need to use a regex like this.
<br>\s?-\s?(.*?)(?=<br>)
Here is an example on your text https://regex101.com/r/71cHQB/1
I hope this can help you.
Also don't forget the /g after the regex so it doesn't stop after the first match.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论