Python 如何替换以特定字符结尾的所有单词?
我有这样的HTMLPython 如何替换以特定字符结尾的所有单词?,python,regex,Python,Regex,我有这样的HTML <b>Source:</b> <a href=\'http://archive.ics.uci.edu/ml/datasets/Iris\'>UCI Machine Learning Repository</a><br>Creator: <br>R.A. Fisher<br>Donor: <br>Michael Marshall (MARSHALL%<u>PLU <
<b>Source:</b> <a href=\'http://archive.ics.uci.edu/ml/datasets/Iris\'>UCI Machine Learning Repository</a><br>Creator: <br>R.A. Fisher<br>Donor: <br>Michael Marshall (MARSHALL%<u>PLU <b>\'@\'</b> io.arc.nasa.gov</u>)<br><b>Abstract:</b> Famous database; from Fisher, 1936<br><b>Data Set Information:</b> This is perhaps the best known database to be found in the pattern recognition literature. Fisher\'s paper is a classic in the field and is referenced frequently to this day. (See Duda & Hart, for example.) The data set contains 3 classes of 50 instances each, where each class refers to a type of iris plant. One class is linearly separable from the other 2; the latter are NOT linearly separable from each other.<br>Predicted attribute: class of iris plant.<br>This is an exceedingly simple domain.<br>This data differs from the data presented in Fishers article (identified by Steve Chadwick, <u>spchadwick <b>\'@\'</b> espeedaz.net</u> ). The 35th sample should be: 4.9,3.1,1.5,0.2,"Iris-setosa" where the error is in the fourth feature. The 38th sample: 4.9,3.6,1.4,0.1,"Iris-setosa" where the errors are in the second and third features. <br><b>Attribute Information:</b><br> 1. sepal length in cm<br> 2. sepal width in cm<br> 3. petal length in cm<br> 4. petal width in cm<br> 5. class: <br> -- Iris Setosa<br> -- Iris Versicolour<br> -- Iris Virginica
来源:
创建者:
R.A.Fisher
捐赠者:
迈克尔·马歇尔(Marshall%PLU\'@\'io.arc.nasa.gov)
摘要:著名数据库;来自Fisher,1936
数据集信息:这可能是模式识别文献中最著名的数据库。费舍尔的论文是该领域的经典之作,至今仍被频繁引用。(例如,参见Duda&;Hart。)数据集包含3个类别,每个类别有50个实例,其中每个类别指的是一种iris植物。一类与另两类是线性可分的;后者之间不是线性可分的。
预测属性:鸢尾属植物的类别。
这是一个非常简单的领域。
该数据与Fishers文章中的数据不同(由Steve Chadwick,spchadwick\'@\'espedaz.net确定)。第35个样本应为:4.9,3.1,1.5,0.2,“Iris setosa”,其中误差在第四个特征中。第38个样本:4.9,3.6,1.4,0.1,“Iris setosa”,其中错误出现在第二和第三个特征中
属性信息:
1。萼片长度在厘米
2。萼片宽度在厘米
3。花瓣长度以厘米为单位
4。花瓣宽度(厘米)
5。类别:毛鸢尾
我想将以:
(冒号)结尾的所有单词都包装在
标记中
Python中的正则表达式是如何做到这一点的
我尝试过这个正则表达式\b(\w+:)\b
,但它不起作用。尝试一下这个正则表达式:
<b>[A-Za-z ]{1,}\:</b>
[A-Za-z]{1,}\:
将所有这些单词提取到一个列表中,然后执行任何您想执行的处理。试试这个正则表达式:
<b>[A-Za-z ]{1,}\:</b>
[A-Za-z]{1,}\:
将所有这些单词提取到一个列表中,然后执行您想要执行的任何处理。这是您需要的正则表达式
\w+:
这是您需要的正则表达式
\w+:
重新导入
regex=“带冒号的粗体字符串:”
matchObj=re.match(r'(.*):',正则表达式,0)
如果匹配对象:
打印matchObj.group()
重新导入
regex=“带冒号的粗体字符串:”
matchObj=re.match(r'(.*):',正则表达式,0)
如果匹配对象:
打印matchObj.group()
try-in-try-in