次の文字列があります。
1) Beach Cottage (CP)
2) Beach Cottage (AP)
3) Cotta (GAP)
( )
そして、私は最初からそれの間のsubstingを取得したいですCP
次の文字列があります。
1) Beach Cottage (CP)
2) Beach Cottage (AP)
3) Cotta (GAP)
( )
そして、私は最初からそれの間のsubstingを取得したいですCP
たとえば、これを試してください:
str = "Beach Cottage (CP)"
str.match(/(\((.*)\))/)[2]
regx でもスキャンを使用できます。
str = "Beach Cottage (CP)"
needed_sub_str = str.scan(/\((.*)\)/)
puts "expected sub string :: #{needed_sub_str}"
出力::
expected sub string :: CP