diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index b329334a332..b77160cc373 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -8386,7 +8386,7 @@ function count_words($string) {
# Start of close tag.
(?! # Do not match any of these specific close tag names.
a> | b> | del> | em> | i> |
- ins> | s> | small> |
+ ins> | s> | small> | span> |
strong> | sub> | sup> | u>
)
\w+ # But, apart from those execptions, match any tag name.
diff --git a/lib/tests/moodlelib_test.php b/lib/tests/moodlelib_test.php
index f10155671b3..a808818672f 100644
--- a/lib/tests/moodlelib_test.php
+++ b/lib/tests/moodlelib_test.php
@@ -4003,6 +4003,7 @@ EOF;
[2, "one\ftwo"],
[1, "SO42-"],
[6, '4+4=8 i.e. O(1) a,b,c,d I’m black&blue_really'],
+ [1, 'ab'],
];
}