Skip to main content
2 of 4
Minor formatting
Chris Davies
  • 128k
  • 16
  • 178
  • 323

how can extract single character before the number in a string

I have a list that contains the names of hosts available in our company.

For example :

  • gswast03
  • gkjbossp1
  • frdwop04

The last characters t, p, q before the number represent the environment of the host. All strings end with a number.

  • t for test
  • p for prod
  • q for qas

I need a reqular expression to obtain the character that is leading to number at the and of the host name (I need a solution for a single string not all list in a file)

For example :

gswas**t**03   : In this string, I just want to extract **t** character.

Thank you in advance.