4

I want to uppercase the last character in a address field. So for "300 E.87th St. #4b" becomes "300 E.87th St. #4B", but "87th" should not change to 87Th. Can I do that in TextMate? If so, what's the syntax?

Thanks.

michaelmcandrew
  • 179
  • 2
  • 14
hadenp
  • 445
  • 3
  • 9
  • Do you mean `87tH`? We need more specific rules for when to capitalize – Explosion Pills Jun 04 '13 at 16:18
  • I want to find a digit followed by an alpha, but only affect the last character in the address field which may be an apartment #. It should capitalize the 'b' but not the 't' (or any other character in the field). – hadenp Jun 04 '13 at 16:25
  • `\d([a-z])$` may find it – Explosion Pills Jun 04 '13 at 17:06
  • ([0-9][a-z]$) in the Find field will capture '4b' but \u$1 in the Replace doesn't do anything. I think because the change case only should be applied to 'b', not '4b'. How do I do indicate that? Or am I wrong in thinking the change case action goes in the Replace field? – hadenp Jun 04 '13 at 21:54
  • In other words, since the capture is '4b', how do indicate change the second char in the capture to uppercase. – hadenp Jun 04 '13 at 22:01

1 Answers1

6

The solution was to simply to have two captures in the Find field: ([0-9])([a-z])$ and include both of them in the Replace: $1\U$2.

Kind of obvious, I guess. This was the first time I've needed regex and was trying to solve a problem while learning the basics, a situation that is doubtless quite common!

hadenp
  • 445
  • 3
  • 9