diff --git a/CHANGELOG.md b/CHANGELOG.md
index 03028df2..6b3a6531 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
+### Fixed
+* Fix ScanPoliciesManager support for compiled regexes
+
 ### Infrastructure
 * Fix readthedocs build by updating to v2 configuration schema
 * Fix spellcheck erroring out on LICENSE file
diff --git a/b2sdk/scan/policies.py b/b2sdk/scan/policies.py
index e6a05396..349a76fd 100644
--- a/b2sdk/scan/policies.py
+++ b/b2sdk/scan/policies.py
@@ -43,7 +43,7 @@ class RegexSet:
         return any(c.match(s) is not None for c in self._compiled_list)
 
 
-def convert_dir_regex_to_dir_prefix_regex(dir_regex):
+def convert_dir_regex_to_dir_prefix_regex(dir_regex: str | re.Pattern) -> str:
     """
     The patterns used to match directory names (and file names) are allowed
     to match a prefix of the name.  This 'feature' was unintentional, but is
@@ -65,8 +65,10 @@ def convert_dir_regex_to_dir_prefix_regex(dir_regex):
     either the regex ends in '$' or does not.
 
     :param dir_regex: a regular expression string or literal
-    :type dir_regex: str
+    :return: a regular expression string which matches the directory prefix
     """
+    if isinstance(dir_regex, re.Pattern):
+        dir_regex = dir_regex.pattern
     if dir_regex.endswith('$'):
         return dir_regex[:-1] + r'/'
     else:

diff --git a/test/unit/scan/test_scan_policies.py b/test/unit/scan/test_scan_policies.py
index fe79c9a4..2c6cd2fc 100644
--- a/test/unit/scan/test_scan_policies.py
+++ b/test/unit/scan/test_scan_policies.py
@@ -70,3 +70,15 @@ class TestScanPoliciesManager:
         }
         with pytest.raises(exception):
             ScanPoliciesManager(**kwargs)
+
+    @pytest.mark.apiver(from_ver=2)
+    def test_re_pattern_argument_support(self):
+        kwargs = {
+            param: (re.compile(r".*"),)
+            for param in (
+                "exclude_dir_regexes",
+                "exclude_file_regexes",
+                "include_file_regexes",
+            )
+        }
+        ScanPoliciesManager(**kwargs)

passing compiled regex results in AttributeError
I am using b2sdk-1.24.0.

`b2sdk.v2.ScalPoliciesManager` accepts `Iterable[str | re.Pattern]` for `exclude_dir_regexes`. However, if `exclude_dir_regexes` contains an `re.Pattern` instance, an Attribute error results at `b2sdk/scan/policies.py:70` because `re.Pattern has no attribute 'endswith'`. When regex is `re.Pattern`, `regex.pattern.endswith` must be used.
test/unit/scan/test_scan_policies.py::TestScanPoliciesManager::test_re_pattern_argument_support
test/unit/scan/test_scan_policies.py::TestScanPoliciesManager::test_include_file_regexes_without_exclude test/unit/scan/test_scan_policies.py::TestScanPoliciesManager::test_illegal_regex[exclude_dir_regexes-InvalidArgument] test/unit/scan/test_scan_policies.py::TestScanPoliciesManager::test_illegal_regex[exclude_file_regexes-InvalidArgument] test/unit/scan/test_scan_policies.py::TestScanPoliciesManager::test_illegal_regex[include_file_regexes-InvalidArgument] test/unit/scan/test_scan_policies.py::TestScanPoliciesManager::test_illegal_timestamp[exclude_modified_before-InvalidArgument] test/unit/scan/test_scan_policies.py::TestScanPoliciesManager::test_illegal_timestamp[exclude_modified_after-InvalidArgument]