re = /(?<action>[a-zA-Z]+)@\/(?<dev_path>.*)\/(?<subsystem>[a-zA-z]+)\/(?<name>[a-zA-z]+)/
str = 'change@/devices/soc/9000000.usb/power_supply/usb
change@/devices/soc/9000000.usb/power_supply/usb
change@/devices/virtual/android_usb/android0
change@/devices/soc/99999999.i2c/i2c-3/3-0025/power_supply/battery
change@/devices/soc/9000000.usb/power_supply/usb
change@/devices/soc/9000000.usb/power_supply/usb
change@/devices/soc/soc:usb_charger/power_supply/usb_charger
change@/devices/soc/soc:mains_charger/power_supply/mains_charger
change@/devices/soc/99999999.i2c/i2c-3/3-0025/power_supply/battery
change@/devices/soc/99999999.i2c/i2c-3/3-0025/power_supply/battery
change@/devices/soc/99999999.i2c/i2c-3/3-0025/power_supply/battery
change@/devices/soc/soc:usb_charger/power_supply/usb_charger
change@/devices/soc/soc:mains_charger/power_supply/mains_charger
change@/devices/soc/99999999.i2c/i2c-3/3-0025/power_supply/battery
'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html