This forum has been very helpful in solving my newbie questions. Thanks!
Now I need help again with this:
I have an array that contains concatenated names of certain keystrokes:
keystrokes=[
VK_A, # the letter a on the keyboard
VK_A_CTRL_SHIFT, # Ctrl+Shift+a
VK_A_SHIFT, # Shift+a
VK_DOWN, # the ArrowDown key
VK_DOWN_SHIFT # Shift+ArrowDown
]
I am looking for a regex that returns the ‘VK_A’ part in the first 3
cases and ‘VK_DOWN’ in the last 2 cases.
results = keystrokes.map do |str|
if md = str.match(/
\A #start of string
[^]+ #not an underscore 1 or more times
_ #an underscore
[^]+ #not an underscore 1 or more times
/xms)
results = keystrokes.map do |str|
md = str.match(/
\A #start of string
[^]+ #not an underscore 1 or more times
_ #an underscore
[^]+ #not an underscore 1 or more times
/xms)
if md
md[0]
else
‘’
end
end
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.