user3390013
user3390013

Reputation: 23

simple regex expression quandry

I have a string like test_validation_v4_0_1-f that I would like to split into 2 pieces: test_validation and 4_0_1-f, the best I've gotten so far is:

import re
r = re.compile(r'_v(\d+)')
print r.split('test_validation_v4_0_1-f')

The results are:

['test_validation', '4', '_0_1-f']

The result I want is:

['test_validation', '4_0_1-f']

Thanks in advance for any help

Upvotes: 1

Views: 28

Answers (1)

Sabuj Hassan
Sabuj Hassan

Reputation: 39405

This one will do for you. It will check for digits ahead but will not pick in expression.

r = re.compile(r'_v(?=\d+)')

Upvotes: 2

Related Questions