fix(analyzer): remove erroneous anchor in Italian driver license regex#1899
Merged
SharonHart merged 1 commit intomicrosoft:mainfrom Mar 9, 2026
Merged
Conversation
The regex for U1-format Italian driver licenses had an erroneous ^ anchor that prevented matching when the license number was not at the start of the string. This fix removes the anchor so licenses like U1K711J11M are correctly recognized regardless of position in text.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes the Italian driver license recognizer so U1-format licenses are detected even when they appear mid-string (issue #1555).
Changes:
- Removed an unintended
^start-of-string anchor from the U1 driver license regex. - Added unit tests to cover U1 licenses containing
J/Kand licenses appearing later in text.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| presidio-analyzer/presidio_analyzer/predefined_recognizers/country_specific/italy/it_driver_license_recognizer.py | Updates the U1 regex alternative to no longer require start-of-string matching. |
| presidio-analyzer/tests/test_it_driver_license_recognizer.py | Adds regression tests for the fixed matching behavior and for J/K letters in U1 licenses. |
You can also share your feedback on Copilot code review. Take the survey.
...sidio_analyzer/predefined_recognizers/country_specific/italy/it_driver_license_recognizer.py
Show resolved
Hide resolved
Contributor
SharonHart
approved these changes
Mar 9, 2026
Br1an67
added a commit
to Br1an67/presidio
that referenced
this pull request
Mar 18, 2026
microsoft#1899) The regex for U1-format Italian driver licenses had an erroneous ^ anchor that prevented matching when the license number was not at the start of the string. This fix removes the anchor so licenses like U1K711J11M are correctly recognized regardless of position in text. Co-authored-by: root <root@C20251020184286.local>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1555
Change Description
Fixed the regex pattern in
ItDriverLicenseRecognizerby removing an erroneous^anchor that prevented matching Italian driver license numbers (U1 format) when they appeared anywhere other than the start of a string.The regex for U1-format licenses incorrectly had
^[U]1which only matched at the beginning of a line. This has been corrected toU1so licenses likeU1K711J11Mare now correctly recognized regardless of their position in the text.Issue reference
Fixes #1555
Checklist
Changes
presidio-analyzer/presidio_analyzer/predefined_recognizers/country_specific/italy/it_driver_license_recognizer.py: Removed erroneous^anchor from the U1-format regex patternpresidio-analyzer/tests/test_it_driver_license_recognizer.py: Added test cases for license numbers containing J/K letters and for licenses not at the start of text