Reputation: 455
I want to match any word except
(-(-)?\w*(=\w*)?)
Example input:
test --par2 --par23=whatever 0 xd true hello "string test"
test --par23=whatever 0 xd true hello --par2 "string test"
test 0 xd "string test" true hello --par2 --par23=whatever
What I want is:
0, xd, true, hello, "string test"
I don't want: test
, --par2
and --par23=whatever
Language: JavaScript
What would be a good idea?
Upvotes: 0
Views: 89
Reputation: 18515
See The Trick. How about matching what you don't need but capturing what you need.
don't want
^\S+
one or more non whitespaces at start (\S
is negation of short \s
)\W-\S+
strings like -foo
, --bar
but want bar-baz
(\W
for non word character)but (
capture )
"[^"]+"
any quoted stuff (using negated class)\S+
one or more remaining non whitespacesOrder according matching priority and combine with pipes |
("[^"]+")|^\S+|\W-\S+|(\S+)
See demo at regex101. Grab captures of the two groups like in this fiddle.
[ "0", "xd", "true", "hello", ""string test"" ]
If using PCRE you can skip the unneeded stuff by use of verbs (*SKIP)(*F)
.
Upvotes: 1
Reputation: 195089
I hope I understood you right, do you mean this?
=\S* ([^=]*)
read the matched text in group1.
Upvotes: 0