Save regex match as string?

How do you save them? As a string?

x = Dir.pwd
=> C:\users\pc\desktop

y = /^[(a-z)]:/i
=> /^[(a-z)]:/i

z = ?

y is regex that matches first occurrence of a-z with : (e.g c:,b:,x:,z:)

z should only hold the drive name (e.g c:,b:,x:,z:)

cynic limbu wrote in post #1162626:

x = Dir.pwd
y = /^([(a-z)]):/i
if x=~y
z=$1
end

If you’re only after a drive letter:
z = Dir.pwd[0]
=> “C”

To assign directly to a variable from a match:
/(?^[(a-z)]):/i =~ Dir.pwd
z
=>“C”

cynic limbu wrote in post #1162673:

Thanks guys!

x = Dir.pwd
x[0,1]
x.reverse[-1]

x[/^(.):/,1]
/^(.):/.match(x)[1]
/^.(?:)/.match(x)[0]

Next game : how many distinct solutions for this exercise ?

Thanks guys!

I found an alternative though.
It is

get_path = Dir.pwd
regex_drive = /^[(a-z)]:/i

my_match = regex_drive.match(get_path).to_s
puts my_match

The only difference is I get the colon ‘:’ too instead of just the drive
letter, sorry If my question was confusing.

Regis d’Aubarede wrote in post #1162708:

cynic limbu wrote in post #1162673:

Thanks guys!

Next game : how many distinct solutions for this exercise ?

Huh? I didn’t understand what you mean by.