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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:16:40+00:00 2026-05-22T00:16:40+00:00

How can I match an optional character in a regex expression? I am trying

  • 0

How can I match an optional character in a regex expression?

I am trying to write a small file that does a little housekeeping to our NAS.

The script goes through the folders inside the specified root folder.

For my testing the root is C:\Users\Solignis\Desktop\Orders

This is where I have the first match take place, it checks to be sure the file matches our standard name convention which is the city + 3 digit folder + 3 digit file number.

Sometimes though we have extra files that have a _1 or _2 on them to denote an additional page.

How can I make this regex expression also fit the “optional” _1 or _2 and sometimes _3 into the match?

The code:

$file =~ /^ ((C[A|F|L]|ME)) (\d{3}) (\d{3}) \. (PDF) /xmi

I am sure this is easy bit I still got loops on the brain from having to “drill” into this giant hash of arrays I made which is something like 25k files in some of the arrays.

Any help would be much appreciated.

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-22T00:16:41+00:00Added an answer on May 22, 2026 at 12:16 am

    Something like (_[1-3])?

    ? Matches zero or one instance.

    might be what you are looking for.

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

Sidebar

Related Questions

In Perl \S matches any non-whitespace character. How can I match any non-whitespace character
[tag]foobar[/tag] [tag parameter1]foobar[/tag] [tag parameter2=whatever]foobar[/tag] [tag parameter1 parameter2=whatever]foobar[/tag] [tag parameter2=whatever parameter1]foobar[/tag] Can I match
I want to extract some phone numbers that are in a local text file
I would like to match the following com.my.company. moduleA .MyClassName com.my.company. moduleB .MyClassName com.my.company.
How does the following code work even though the signature of the function in
I have a .txt file created in Windows and now should be edited in
I'm debugging a route matching issue in ASP.NET MVC. The URL is defined like
What is the best way, in Javascript, to use an array as a key
Due to limitations in my script, I've come across a problem where I need
I've got the following source: <font color=black>0</font><font color=white>1101100001001101</font><font color=black>1</font><font color=white>0110</font> And would like to

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.