diff options
-rw-r--r-- | doc/source/index.rst | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/doc/source/index.rst b/doc/source/index.rst index 16c6020..e5e3fbc 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -1026,16 +1026,23 @@ A regular expression ^^^^^^^^^^^^^^^^^^^^ If you pass in a regular expression object, Beautiful Soup will filter -against that regular expression. This code finds all the tags whose -names start with the letter "b"; in this case, the <body> tag and the -<b> tag:: +against that regular expression using its ``match()`` method. This code +finds all the tags whose names start with the letter "b"; in this +case, the <body> tag and the <b> tag:: import re - for tag in soup.find_all(re.compile("b.*")): + for tag in soup.find_all(re.compile("^b")): print(tag.name) # body # b +This code finds all the tags whose names contain the letter 't':: + + for tag in soup.find_all(re.compile("t")): + print(tag.name) + # html + # title + .. _a list: A list |