Python: pattern matching(?)

175 views Asked by At

I am a beginner in Python programming and I have a question about constructing a 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 pattern bbb \t (one digit or character not a) \t, I would replace the bbb \t digit \t with bbb_$d$_. (Here, \t indicates tab and bbb indicates a number).

Thus, the output would be 150_$z$_Brazil, and the output for 160 a Toys R Us would not be obtained as the digit after 160 is a.

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

1

There are 1 answers

1
Raymond Hettinger On BEST ANSWER

Q. how do I code such that I select one digit or character that is not a?

A. '[^a]'

The regular expression syntax is documented here.