Use raw strings for regexps in Python code.

Starting with Python 3.12, use of unescaped backslash in strings is
reported as a SyntaxWarning, and may become an error at a later time.
Backslashes are commonly found in regexp code.

Using raw strings fixes the syntax problem, and it's something that
newer code is already doing, so it fits nicely within the codebase.

Bug: 1487454
Change-Id: I8d42cc3f31da583544ab094d454ef29051e184f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4969774
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Jacobo Aragunde Pérez <jaragunde@igalia.com>
Reviewed-by: Oksana Zhuravlova <oksamyt@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1215379}
diff --git a/build/android/gyp/java_cpp_enum.py b/build/android/gyp/java_cpp_enum.py
index 5225b89..c49f0178 100755
--- a/build/android/gyp/java_cpp_enum.py
+++ b/build/android/gyp/java_cpp_enum.py
@@ -189,8 +189,9 @@
   enum_name_re = r'(\w+)'
   optional_fixed_type_re = r'(\:\s*(\w+\s*\w+?))?'
   enum_start_re = re.compile(r'^\s*(?:\[cpp.*\])?\s*enum\s+' +
-      optional_class_or_struct_re + '\s*' + enum_name_re + '\s*' +
-      optional_fixed_type_re + '\s*{\s*')
+                             optional_class_or_struct_re + r'\s*' +
+                             enum_name_re + r'\s*' + optional_fixed_type_re +
+                             r'\s*{\s*')
   enum_single_line_re = re.compile(
       r'^\s*(?:\[cpp.*\])?\s*enum.*{(?P<enum_entries>.*)}.*$')
 
diff --git a/build/android/gyp/util/build_utils.py b/build/android/gyp/util/build_utils.py
index 938c7041..5b1473e 100644
--- a/build/android/gyp/util/build_utils.py
+++ b/build/android/gyp/util/build_utils.py
@@ -456,7 +456,7 @@
   """
   new_args = list(args)
   file_jsons = dict()
-  r = re.compile('@FileArg\((.*?)\)')
+  r = re.compile(r'@FileArg\((.*?)\)')
   for i, arg in enumerate(args):
     match = r.search(arg)
     if not match:
diff --git a/build/write_buildflag_header.py b/build/write_buildflag_header.py
index 89a07376..a8b68f9 100755
--- a/build/write_buildflag_header.py
+++ b/build/write_buildflag_header.py
@@ -44,7 +44,7 @@
   header_guard = cmdline_options.output.upper()
   if header_guard[0].isdigit():
     header_guard = '_' + header_guard
-  header_guard = re.sub('[^\w]', '_', header_guard)
+  header_guard = re.sub(r'[^\w]', '_', header_guard)
   header_guard += '_'
 
   # The actual output file is inside the gen dir.
diff --git a/components/variations/service/generate_ui_string_overrider.py b/components/variations/service/generate_ui_string_overrider.py
index 9a3c139..32b903ccf 100755
--- a/components/variations/service/generate_ui_string_overrider.py
+++ b/components/variations/service/generate_ui_string_overrider.py
@@ -20,7 +20,7 @@
 #   #define IDS_FOO_MESSAGE 1234
 # With generate allowlist flag:
 #   #define IDS_FOO_MESSAGE (::ui::AllowlistedResource<1234>(), 1234)
-RESOURCE_EXTRACT_REGEX = re.compile('^#define (\S*).* (\d+)\)?$', re.MULTILINE)
+RESOURCE_EXTRACT_REGEX = re.compile(r'^#define (\S*).* (\d+)\)?$', re.MULTILINE)
 
 class Error(Exception):
   """Base error class for all exceptions in generated_resources_map."""
diff --git a/mojo/public/tools/bindings/concatenate_and_replace_closure_exports.py b/mojo/public/tools/bindings/concatenate_and_replace_closure_exports.py
index 770081e1..7d56c9f 100755
--- a/mojo/public/tools/bindings/concatenate_and_replace_closure_exports.py
+++ b/mojo/public/tools/bindings/concatenate_and_replace_closure_exports.py
@@ -32,7 +32,7 @@
     return
 
   if line.startswith("goog.provide"):
-    match = re.match("goog.provide\('([^']+)'\);", line)
+    match = re.match(r"goog.provide\('([^']+)'\);", line)
     if not match:
       print("Invalid goog.provide line in %s:\n%s" % (filename, line))
       sys.exit(1)
diff --git a/tools/generate_stubs/generate_stubs.py b/tools/generate_stubs/generate_stubs.py
index 0093fc6..25e4da3 100755
--- a/tools/generate_stubs/generate_stubs.py
+++ b/tools/generate_stubs/generate_stubs.py
@@ -69,12 +69,12 @@
 # From that, all preceding characters are considered the return value.
 # Trailing characters should have a substring matching the form (.*).  That
 # is considered the arguments.
-SIGNATURE_REGEX = re.compile('(?P<return_type>.+?)'
-                             '(?P<name>[_a-zA-Z][_a-zA-Z0-9]+)\s*'
-                             '\((?P<params>.*?)\)')
+SIGNATURE_REGEX = re.compile(r'(?P<return_type>.+?)'
+                             r'(?P<name>[_a-zA-Z][_a-zA-Z0-9]+)\s*'
+                             r'\((?P<params>.*?)\)')
 
 # Used for generating C++ identifiers.
-INVALID_C_IDENT_CHARS = re.compile('[^_a-zA-Z0-9]')
+INVALID_C_IDENT_CHARS = re.compile(r'[^_a-zA-Z0-9]')
 
 # Constants defining the supported file types options.
 FILE_TYPE_WIN_X86 = 'windows_lib'
@@ -661,7 +661,7 @@
 
     # Generate the argument list.
     arguments = [
-        re.split('[\*& ]', arg)[-1].strip() for arg in signature['params']
+        re.split(r'[\*& ]', arg)[-1].strip() for arg in signature['params']
     ]
     # Remove square brackets from arrays, otherwise we will end with a
     # compilation failure.