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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:51:42+00:00 2026-06-11T10:51:42+00:00

I have tried stuff like =~ \[[A-Za-z0-9]+\] which I would expect would work but

  • 0

I have tried stuff like =~ "\[[A-Za-z0-9]+\]" which I would expect would work but doesnt. I also tried "[[A-Za-z0-9]+]" and "\[[:alnum:]+\]". What am I doing wrong? Sample line I want to match: [RTNUT18] (I am iterating through a file, some lines are of this form)

This is my code snippet:

while read line;
do
    if [[ $line =~ "^\[[A-Za-z0-9]+\]$" ]]; then
        echo match
    else
        echo no match
    fi
done < $1

This is a sample file:

[RBPAT7]
Whatever=foo,bla
Otherline
RRR

and I run:

./script.sh thefile.txt

I am not getting a hit on the [RBPAT7] line at all

  • 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-11T10:51:44+00:00Added an answer on June 11, 2026 at 10:51 am

    Stuff like that isn’t enough. You must use it in [[.

    $ [[ [foo] =~ ^\[[A-Za-z0-9]+\]$ ]] ; echo $?
    0
    

    EDIT:

    Unlike test, [[ does not need quotes around its arguments. Your code matches nothing, since you can’t have " before the beginning of the line, nor " after the end. Remove the quotes.

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

Sidebar

Related Questions

I'm a noob so this is probably basic stuff, but I have tried to
I have tried many permutations but they all don't seems to work well. Am
I feel like I'm missing something here, but I have this datagrid which when
Guys, I HAVE tried reading tons of stuff about EJB. And I don't get
I have tried searching over the internet about this problem but not able to
I have a bunch of XML files which are using prefixes but without the
I am working on a webby, which would need unique user identification like IP/MAC
I have a website with a standard PHP login system, nothing special, but would
I would like to write simple scripts in C#. Stuff I would normally use
I want to have a JTextField (or another text-like input which supports focus and

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.