diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index 4a77f0c..ebe3cc1 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -735,7 +735,7 @@ def _parse(source, state, verbose):
if flags is None: # global flags
if pos != 3: # "(?x"
import warnings
- warnings.warn('Flags not at the start of the expression',
+ warnings.warn('Flags not at the start of the expression %s' % source.string,
DeprecationWarning, stacklevel=7)
continue
add_flags, del_flags = flags
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index eb1aba3..4da3cdf 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -1323,7 +1323,8 @@ class ReTests(unittest.TestCase):
self.assertTrue(re.match('(?ixu) ' + upper_char, lower_char))
self.assertTrue(re.match('(?ixu) ' + lower_char, upper_char))
- with self.assertWarns(DeprecationWarning):
+ msg = 'Flags not at the start of the expression (?i)'
+ with self.assertWarnsRegex(DeprecationWarning, msg):
self.assertTrue(re.match(upper_char + '(?i)', lower_char))
def test_dollar_matches_twice(self):