Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 832325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:20:41+00:00 2026-05-15T04:20:41+00:00

i Have an arguments like the one below which i pass to powershell script

  • 0

i Have an arguments like the one below which i pass to powershell script

-arg1 -abc -def -arg2 -ghi -jkl -arg3 -123 -234

Now i need to extract three strings without any whitespace

string 1: "-abc -def" 

string 2: "-ghi -jkl"

string 3: "-123 -234"

i figured this expression could do it. But this doesnt seem to work.

$args -match '-arg1(?'arg1'.*?) -arg3(?'arg3'.*?) -arg3(?'arg3'.*)'. 

THis should return $matches[‘arg1’] etc. So whats wrong in above expression. Why do i get an error as shown below

runScript.ps1 -arg1 -abc -def -arg2 -ghi -jkl -arg3 -123 -234

Unexpected token 'arg1'.*?) -arg2
(?'arg2'.*?) -arg3 (?'arg3'.*)'' in
expression or statement. At
G:\powershell\tools\powershell\runTest.ps1:1
char:71
+ $args -match '-arg1 (?'arg1'.*?) -arg2 (?'arg2'.*?) -arg3 (?'arg3'.*)' <<<<
    + CategoryInfo          : ParserError: (arg1'.*?) -arg2...g3
(?'arg3'.*)':String) [],
ParseException
    + FullyQualifiedErrorId : UnexpectedToken

and also the second question is how do i make arg1 or arg2 or arg3 optional?

The argument to script can be

-arg2 -def -ghi.

I’ll take some default values for arg(1|2|3) that is not mentioned.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:20:42+00:00Added an answer on May 15, 2026 at 4:20 am

    seems like the stack overflow syntax highlighter already spoils it for you: you’re double-using the ‘ character; for named groups, and for the entire string.

    I can’t try as i dont have PS on this box, but what about:

    $args -match '-arg1(?<arg1>.*?) -arg2(?<arg2>.*?) -arg3(?<arg3>.*)'
    

    ?

    additionally, i would replace the spaces with \s+, so that multiple whitespace characters between the parameters are also allowed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 512k
  • Answers 512k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Ok.. it was stupid. I use stupid ″ instead of… May 16, 2026 at 5:37 pm
  • Editorial Team
    Editorial Team added an answer You don't need to do anything in code-behind if you… May 16, 2026 at 5:37 pm
  • Editorial Team
    Editorial Team added an answer Let's say, you want to call Foo from b.aspx from… May 16, 2026 at 5:37 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a table which contain 100 rows and td. like see below <table
I have a function that works like that: (the-function [one] [two] [three]) and I
Another one I can't find an answer for, and it feels like I've gone
PHP mysql database I have created a follow on question to this one here
I have a .NET assembly which I am accessing from VBScript (classic ASP) via
I'm programming in C here, for Windows and various Unix platforms. I have a
I am having a problem with views. I have a view and am passing
Say I have a hash algorithm, and it's nice and smooth (The odds of
I have some WebUserControls that take a parameter to determine how they initialize themselves.
I have a nested switch statement inside a switch statement. I am wondering if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.