-4

I've the following string

1=>    Stephen Avenue 700 Center St SE Calgary, AB T2G5P6

2=> Montgomery 4611 Bowness Rd NW Calgary, AB T3B0S4

3=> Uptown 17th Ave 1022 17 Ave SW Calgary, AB T2T0A5

and I want to get T2G5P6 from first, T3B0S4 from 2nd and T2T0A5 from 3rd using regular expressions Thanks

M K
  • 385
  • 5
  • 14

3 Answers3

6

you can get T2G5P6 using regular expressions. Of course you can.

use this regex :

/T2G5P6/

demo here : http://regex101.com/r/lY8qS6

on a serious note:

if you say these rules about your pincode

  • only six characters
  • only capital letters and digits

then this regex will be helpful for you :

[A-Z0-9]{6}

second demo here : http://regex101.com/r/oA1qL9

aelor
  • 10,892
  • 3
  • 32
  • 48
  • OK, but this is sample query, I mean I want regular expression that could extract this string and same like this string from other strings that I provide to it – M K Apr 09 '14 at 10:30
  • "*same like this string from other strings*" — Without knowing what *you* consider to be "same", we cannot really answer that. – Amal Murali Apr 09 '14 at 10:31
  • @Mubin To be honest, aelor did answer your question. If you update it and be a little more specific I'm sure we'll be glad to help – ScottMcGready Apr 09 '14 at 10:32
1

Use this ([A-Z0-9]{6}) pattern to get the 6 characters from your string

Demo

http://regex101.com/r/wY2tZ5

Nambi
  • 11,944
  • 3
  • 37
  • 49
0

If it always going to be LetterDigitLetterDigitLetterDigit you can use

([a-zA-Z]\d){3}
Martyn
  • 806
  • 1
  • 8
  • 20