Created
March 7, 2018 07:26
-
-
Save lbvf50mobile/02f3e9eedbab9011ce722942a1e336cb to your computer and use it in GitHub Desktop.
regex comments and groups capturing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r_old = /(.*)\/(.*) #this is a comment/x | |
r_new = %r{(?<dir>.*)/(?<file>.*)} | |
r_center_comment = /(.*) # since here it is a coment \/(.*) #this is a comment/x | |
a_old = "directory4/the_file1".match(r_old) | |
a_new = "directory4/the_file1".match(r_new) | |
a_center = "directory4/the_file1".match(r_center_comment) | |
p a_old[1] == a_new[:dir] && a_old[2] === a_new[:file] # true | |
p a_center[1] != a_new[:dir] && a_center[2] != a_new[:file] # true | |
p a_new.names | |
p a_new.captures | |
p a_new.names.zip(a_new.captures).to_h # {"dir"=>"directory4", "file"=>"the_file1"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment