Python: pattern matching (?)

I'm starting to program in Python, and I have a question about creating code.

Let's say I have the following data:

150 z   Brazil
160 a   Toys R Us

I want to code such that if we see the template bbb \t (one digit or character not a) \t, I would replace it bbb \t digit \twith bbb_$d$_. (Here \tindicates the tab and bbbindicates the number).

Thus, the output will be 150_$z$_Brazil, and the output for 160 a Toys R Uswill not be obtained as the figure after 160is equal to a.

My question is: how do I encode such a code so that I select one digit or character that is not a?

+4
source share
1 answer

Q. How can I encode so that I select a single digit or character that is not?

and. '[^a]'

The regular expression syntax is described here .

+5
source

All Articles