相关疑难解决方法(0)

除了XHTML自包含标记之外,RegEx匹配开放标记

我需要匹配所有这些开始标记:

<p>
<a href="foo">
Run Code Online (Sandbox Code Playgroud)

但不是这些:

<br />
<hr class="foo" />
Run Code Online (Sandbox Code Playgroud)

我想出了这个,并希望确保我做对了.我只抓住了a-z.

<([a-z]+) *[^/]*?>
Run Code Online (Sandbox Code Playgroud)

我相信它说:

  • 找一个小于,然后
  • 然后,查找(并捕获)az一次或多次
  • 然后找到零个或多个空格
  • 找到任何字符零次或多次,贪婪/,然后
  • 找到一个大于

我有这个权利吗?更重要的是,你怎么看?

html regex xhtml

1323
推荐指数
36
解决办法
270万
查看次数

如何在string.replace中输入正则表达式?

我需要一些关于声明正则表达式的帮助.我的输入如下:

this is a paragraph with<[1> in between</[1> and then there are cases ... where the<[99> number ranges from 1-100</[99>. 
and there are many other lines in the txt files
with<[3> such tags </[3>
Run Code Online (Sandbox Code Playgroud)

所需的输出是:

this is a paragraph with in between and then there are cases ... where the number ranges from 1-100. 
and there are many other lines in the txt files
with such tags
Run Code Online (Sandbox Code Playgroud)

我试过这个:

#!/usr/bin/python
import os, sys, re, glob
for infile in glob.glob(os.path.join(os.getcwd(), '*.txt')):
    for …
Run Code Online (Sandbox Code Playgroud)

python regex string replace

272
推荐指数
6
解决办法
29万
查看次数

标签 统计

regex ×2

html ×1

python ×1

replace ×1

string ×1

xhtml ×1