2016-11-05 3 views
0

У меня есть 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>\'@\'</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 &amp; 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 

Я хочу, чтобы обернуть все слова внутри тега <b></b> которые заканчивающегося : (толстой кишки)

Что такое Regex в Python, чтобы сделать это?

Я пробовал это регулярное выражение \b(\w+:)\b, но оно не работает.

+0

попробовать в http://regexr.com/ –

ответ

1

Попробуйте RegEx:

<b>[A-Za-z ]{1,}\:</b> 

Fetch все эти слова в списке, а затем делать то, что обработка вы хотите выполнить.

0
import re 

regex = "<b>bold string with colon:</b>" 

matchObj = re.match(r'<b>(.*):</b>', regex, 0) 
if matchObj: 
    print matchObj.group() 
Смежные вопросы