Regular Expressions 101

Community Patterns

Extract ICS Codes from string including several wrong formattings

0

Regular Expression
Python

r"
[^\d\.](((01|03|07|11|13|17|19|21|23|25|27|29|31|33|35|37|39|43|45|47|49|53|55|59|61|65|67|71|73|75|77|79|81|83|85|87|91|93|95|97|99)[\. ]?[\dX]{3}[\. ]?[\dX]{2}[\. \-]?[\dX]{2}|(01|03|07|11|13|17|19|21|23|25|27|29|31|33|35|37|39|43|45|47|49|53|55|59|61|65|67|71|73|75|77|79|81|83|85|87|91|93|95|97|99)[\. ]?[\dX]{3}[\. ]?[\dX]{2}|(01|03|07|11|13|17|19|21|23|25|27|29|31|33|35|37|39|43|45|47|49|53|55|59|61|65|67|71|73|75|77|79|81|83|85|87|91|93|95|97|99)[\. ]?[\dX]{3})(?![\d\.X]))|([^\d\.](01|03|07|11|13|17|19|21|23|25|27|29|31|33|35|37|39|43|45|47|49|53|55|59|61|65|67|71|73|75|77|79|81|83|85|87|91|93|95|97|99)(?![\d\.X]|( ?%)))
"
gm

Description

Matches code including character before the code which must NOT be a digit, dot or minus. Therefore, before analyzing a string, add a space in front of it and after analyzing remove the first character of each match. Lookbehind is not used because VBA doesn't support it.

Submitted by Guido Witt-Dörring - a year ago (Last modified a year ago)