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 8705819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:27:37+00:00 2026-06-13T03:27:37+00:00

With grep , you can use a question mark ? to signify an optional

  • 0

With grep, you can use a question mark ? to signify an optional character, that is a character that is to be matches 0 or 1 times.

$ foo=qwerasdf

$ grep -Eo fx? <<< $foo
f

The question is does Bash String Manipulation have a similar feature? Something like

$ echo ${foo%fx?}
  • 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-06-13T03:27:38+00:00Added an answer on June 13, 2026 at 3:27 am

    You’re probably talking about parameter expansion. It uses shell patterns, not regular expression, so the answer is no.

    Upon further reading, I noticed that if you

    shopt -s extglob
    

    you can use extended pattern matching which can achieve something similar to regex, albeit with slightly different syntax.

    Check this out:

    word="mre"
    # this returns true
    if [[ $word == m?(o)re ]]; then echo true; else echo false; fi
    
    word="more"
    # this also returns true
    if [[ $word == m?(o)re ]]; then echo true; else echo false; fi
    
    word="mooooooooooore"
    # again, true
    if [[ $word == m+(o)re ]]; then echo true; else echo false; fi
    

    Works with parameter expansion too,

    word="noooooooooooo"
    # outputs 'nay'
    echo ${word/+(o)/ay}
    # outputs 'nayooooooooooo'
    echo ${word/o/ay}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We can use grep to return the lines with matched words, but how to
I know I can use the -n flag in git grep to show the
I often use grep and sed in my bash scripts. For example, I use
In bash, one can use env printev to print environment(global) variables, or use set
This question specifies that -P allows GNU grep to grep for a tab grep
In an answer to a previous question: How can I use 'do I have
Using only grep and sed, is there a way I can tranform the output
I have output from grep I'm trying to clean up that looks like: <words>Http://www.path.com/words</words>
I want to grep files that contain text "wp_" but do not contain text
I thought I could just use this related question: How Do I write a

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.