I have following exemplary strings:
- FCF_VD_ID,
- [FCF_VD_Alert_L1, ..., FCF_VD_Alert_L8],
- FCF_VD_SyncID,
- [FCF_VRU_Alert_FCV, FCF_VRU_Alert_A ..., FCF_VRU_Alert_H],
- [COM_Cam_Frame_1, ..., COM_Cam_Frame_8]
And I need to extract some specific parts from these strings. Specifically I need the core name of each string which in the above cases is everything till enumerator. As an enumerator I treat L1->L8, FCV, A->H, 1->8.
As output I need to get two strings:
core, enum = re.match(regex, string)
Example:
FCF_Alert_L1 -> FCF_Alert, L1
FCF_SyncID -> FCF_Sync_ID, None
FCF_VRU_Alert_FCV -> FCF_VRU_Alert, FCV
Unfortunately my regex ^([A-Za-z_]+(ID)?)([A-Z]+\d+|[A-Z]+|\d+)?$ does not work.
Can anybody point out the problem in this regex?
For FCF_VD_ID_L1 I receive ('FCF_VD_ID_L', None, '1') which is completely not what I require.
re.findall(r'(\w+)_(\w+)', text)? Or,(\w+)_(L?\d+|FCV|[AH]|[A-Za-z]*ID)\b? See this regex demo.^([^_\n]+(?:_[^_\n]+)*?)(?:_(L[1-8]|FCV|[A-Z]|[1-8]|ID))?$regex101.com/r/4QnKNy/1