dimanche 21 février 2021

Extract a string between two set of patterns in Python

I am trying to extract a substring between two set of patterns using re.search().

On the left, there can be either 0x or 0X, and on the right there can be either U, , or \n. The result should not contain boundary patterns. For example, 0x1234U should result in 1234.

I tried with the following search pattern: (0x|0X)(.*)(U| |\n), but it includes the left and right patterns in the result.

What would be the correct search pattern?

Aucun commentaire:

Enregistrer un commentaire