Skip to content
Advertisement

Using Python and Regex get last occurrence and remaining part

I’m trying to use python and regex to get the last set of integers in a filename (string) Which the method does what i need, however I want to also return the inverse or remaining parts of the regex. How can i do that?

Here is the regex ([0-9]+|#+)(?!.*([0-9]+|#+))

JavaScript

Currently it is returning…. ('01', None) I’d like it to return something like ('image', '0001')

Updated

Optionally is there a way to split the strings by groups of numbers…for example

JavaScript

Advertisement

Answer

EDIT:

Use

JavaScript

See proof.

Explanation

JavaScript

ORIGINAL: Use re.split, add capturing group to keep captured part inside the result:

JavaScript

See Python proof

Results:

JavaScript

See regex proof.

Explanation

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement