in reply to Extract delimited words from string

you should better use a dedicated module for that, but just for fun

use v5.12; use warnings; while ( <DATA> ) { chomp; say "'$_'"; say $3 while # print 3rd capture $_ =~ /(^|\s) # starts with line's start or white +space ("?) # capture optional double-quote ins +ide (otherwise empty string) ([^\2]*?) # capture anything non-quote \2 # end with same quote (?=(\s|$)) # look-ahead at following whitespac +e or line's end /xg # g= loop _globally_ over all match +es x=allow multiline extended regex } __DATA__ 50 0 "R0 G255 B0 A255" "Solid" 118 1 "R0 G0 B0 A255" "R0 G0 B0 A255" 0 70 0 "R0 G255 B255 A255" "Solid" 118 1 "R12 G12 B12 A255" "R12 G12 B12 + A255" 0

output:

'50 0 "R0 G255 B0 A255" "Solid" 118 1 "R0 G0 B0 A255" "R0 G0 B0 A255" +0' 50 0 R0 G255 B0 A255 Solid 118 1 R0 G0 B0 A255 R0 G0 B0 A255 0 '70 0 "R0 G255 B255 A255" "Solid" 118 1 "R12 G12 B12 A255" "R12 G12 B1 +2 A255" 0' 70 0 R0 G255 B255 A255 Solid 118 1 R12 G12 B12 A255 R12 G12 B12 A255 0

Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery

update

added comments