Skip to main content
deleted 4 characters in body
Source Link
marc_s
  • 759.6k
  • 185
  • 1.4k
  • 1.5k

You could use following Regex for the purpose.

[\""].+?[\""]|[^ ]+

For example,

var commandList = Regex.Matches(baseCommand, @"[\""].+?[\""]|[^ ]+")
                .Cast<Match>()
                .Select(x => x.Value.Trim('"'))
                .ToList();

Sample 1 Input

DoSomething "second arg that has spaces" thirdArguementWithoutSpacesthirdArgumentWithoutSpaces

Output

Command List
------------
DoSomething 
second arg that has spaces
thirdArguementWithoutSpacesthirdArgumentWithoutSpaces

Sample 2 Input

DoSomething "second arg that has spaces" "third ArguementArgument With Spaces"

Output

Command List
------------
DoSomething 
second arg that has spaces
third ArguementArgument With Spaces

You could use following Regex for the purpose.

[\""].+?[\""]|[^ ]+

For example,

var commandList = Regex.Matches(baseCommand, @"[\""].+?[\""]|[^ ]+")
                .Cast<Match>()
                .Select(x => x.Value.Trim('"'))
                .ToList();

Sample 1 Input

DoSomething "second arg that has spaces" thirdArguementWithoutSpaces

Output

Command List
------------
DoSomething 
second arg that has spaces
thirdArguementWithoutSpaces

Sample 2 Input

DoSomething "second arg that has spaces" "third Arguement With Spaces"

Output

Command List
------------
DoSomething 
second arg that has spaces
third Arguement With Spaces

You could use following Regex for the purpose.

[\""].+?[\""]|[^ ]+

For example,

var commandList = Regex.Matches(baseCommand, @"[\""].+?[\""]|[^ ]+")
                .Cast<Match>()
                .Select(x => x.Value.Trim('"'))
                .ToList();

Sample 1 Input

DoSomething "second arg that has spaces" thirdArgumentWithoutSpaces

Output

Command List
------------
DoSomething 
second arg that has spaces
thirdArgumentWithoutSpaces

Sample 2 Input

DoSomething "second arg that has spaces" "third Argument With Spaces"

Output

Command List
------------
DoSomething 
second arg that has spaces
third Argument With Spaces
added 28 characters in body
Source Link
Anu Viswan
  • 18.2k
  • 4
  • 27
  • 53

You could use following Regex for the purpose.

[\""].+?[\""]|[^ ]+

For example,

var commandList = Regex.Matches(baseCommand, @"[\""].+?[\""]|[^ ]+")
                .Cast<Match>()
                .Select(x => x.Value.Trim('"'))
                .ToList().Skip(1);

Sample 1 Input

DoSomething "second arg that has spaces" thirdArguementWithoutSpaces

Output

Command List
------------
DoSomething 
second arg that has spaces
thirdArguementWithoutSpaces

Sample 2 Input

DoSomething "second arg that has spaces" "third Arguement With Spaces"

Output

Command List
------------
DoSomething 
second arg that has spaces
third Arguement With Spaces

You could use following Regex for the purpose.

[\""].+?[\""]|[^ ]+

For example,

var commandList = Regex.Matches(baseCommand, @"[\""].+?[\""]|[^ ]+")
                .Cast<Match>()
                .Select(x => x.Value.Trim('"'))
                .ToList().Skip(1);

Sample 1 Input

DoSomething "second arg that has spaces" thirdArguementWithoutSpaces

Output

Command List
------------
second arg that has spaces
thirdArguementWithoutSpaces

Sample 2 Input

DoSomething "second arg that has spaces" "third Arguement With Spaces"

Output

Command List
------------
second arg that has spaces
third Arguement With Spaces

You could use following Regex for the purpose.

[\""].+?[\""]|[^ ]+

For example,

var commandList = Regex.Matches(baseCommand, @"[\""].+?[\""]|[^ ]+")
                .Cast<Match>()
                .Select(x => x.Value.Trim('"'))
                .ToList();

Sample 1 Input

DoSomething "second arg that has spaces" thirdArguementWithoutSpaces

Output

Command List
------------
DoSomething 
second arg that has spaces
thirdArguementWithoutSpaces

Sample 2 Input

DoSomething "second arg that has spaces" "third Arguement With Spaces"

Output

Command List
------------
DoSomething 
second arg that has spaces
third Arguement With Spaces
added 424 characters in body
Source Link
Anu Viswan
  • 18.2k
  • 4
  • 27
  • 53

You could use following Regex for the purpose.

[\""].+?[\""]|[^ ]+

For example,

var commandList = Regex.Matches(baseCommand, @"[\""].+?[\""]|[^ ]+")
                .Cast<Match>()
                .Select(x => x.Value.Trim('"'))
                .ToList().Skip(1);

Sample 1 Input

DoSomething "second arg that has spaces" thirdArguementWithoutSpaces

Output

Command List
------------
second arg that has spaces
thirdArguementWithoutSpaces

Sample 2 Input

DoSomething "second arg that has spaces" "third Arguement With Spaces"

Output

Command List
------------
second arg that has spaces
third Arguement With Spaces

You could use following Regex for the purpose.

[\""].+?[\""]|[^ ]+

For example,

var commandList = Regex.Matches(baseCommand, @"[\""].+?[\""]|[^ ]+")
                .Cast<Match>()
                .Select(x => x.Value.Trim('"'))
                .ToList().Skip(1);

You could use following Regex for the purpose.

[\""].+?[\""]|[^ ]+

For example,

var commandList = Regex.Matches(baseCommand, @"[\""].+?[\""]|[^ ]+")
                .Cast<Match>()
                .Select(x => x.Value.Trim('"'))
                .ToList().Skip(1);

Sample 1 Input

DoSomething "second arg that has spaces" thirdArguementWithoutSpaces

Output

Command List
------------
second arg that has spaces
thirdArguementWithoutSpaces

Sample 2 Input

DoSomething "second arg that has spaces" "third Arguement With Spaces"

Output

Command List
------------
second arg that has spaces
third Arguement With Spaces
Source Link
Anu Viswan
  • 18.2k
  • 4
  • 27
  • 53
Loading