0
a = 'foo<99>bar'
match = re.findall(r'(<\d(\d)>)',a)

## match gives [('<99>', '9')] but I would to have ['<99','9>']

I tried to escape the '(' but, the regex engine takes it a literal '('

2 Answers 2

1

You don't need grouping if you want that your output be ['<99','9>'] you can use pip:

r'<\d+|\d+>' .

Sign up to request clarification or add additional context in comments.

Comments

0

use this pattern

(?=(<\d+>))|(?=(\d>))

Demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.