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

  • Home
  • SEARCH
  • 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 7539427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:22:44+00:00 2026-05-30T07:22:44+00:00

Having trouble determining if a file name conforms to a specific convention as follows.

  • 0

Having trouble determining if a file name conforms to a specific convention as follows. Using regular expression in C# .Net 4.0.

Valid Format: xxxxT_SSS_sss[i]_t#y.png
where

// x = Any single character.
// T = Digit: 1 to 7 inclusive.
// _SSS = Positive Integer: 000 to 999 inclusive. Always padded with leading zeros.
// _sss = Positive Integer: 000 to 999 inclusive. Always padded with leading zeros.
// i = Random text of any length including any characters. Will always be enclosed in square [] brackets. Optional.
// _t = Positive Integer: 0 to 999 inclusive. Not padded. Optional.
// #y = Positive Integer: 0 to 999 inclusive. Not padded. Optional.

UPDATE

Valid file names:

File1_000_000.png
File1_000_000_1.png
File1_000_000#2.png
File1_000_000_1#2.png
File1_000_000[text].png
File1_000_000[text]_1.png
File1_000_000[text]#2.png
File1_000_000[text]_1#2.png

The regex I’ve been trying is:

^(.{4}\\d_\\d{3}_\\d{3}(\\[\\w\\s]+\\])?(_\\d{1,3})?(\\#\\d{1,3})?)

This returns true for all the sample file names BUT, if I change File1_000_000[text]_1#2.png to File1_000_000[text]_#2.png by deleting the digit 1, it still returns true. The underscore is a part of the _t.

  • 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-30T07:22:45+00:00Added an answer on May 30, 2026 at 7:22 am

    A question on regex that doesn’t involve HTML parsing, is a rarity!

    Try the following:

    @"^.{4}[2-7](_\d{3}){2}(\[.*?\])?(_\d{1,3})?(#\d{1,3})?\.png$"
    

    This breaks down into:

    ^             Start of string
    .{4}          Any character, exactly 4 times
    [2-7]         A number in the range 2 - 7 once
    (_\d{3}){2}   An underscore followed by 3 numbers, twice
    (\[.*?\])?    An opening square bracket followed by any number of characters and closed by a square bracket 0 or 1 times
    (_\d{1,3})?   An underscore followed by at least 1 and up to 3 numbers 0 or 1 times
    (#\d{1,3})?   A pound (#) followed by at least 1 and up to 3 numbers 0 or 1 times
    \.png$        Ending in .png
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having trouble using a .NET COM in vb6, It compiles ok and I
I'm having trouble determining a way to parse a given text file. Here is
I'm having trouble determining the file-type of an image I uploaded with Zend Framework.
I'm having some trouble determining what's going on with simplexml_load_string() I'm using the below
I'm having trouble determining if it's possible, based on the amount of access I
I having trouble in dividing the HTML frames. I have been using the following
Im having trouble reading from a CSV file final String DELIMITER = ,; Scanner
I'm having trouble determining the best way to read some input in for a
I was having trouble determining what was cause my form to not submit when
I'm having trouble determining the difference between CREATE SCHEMA and CREATE DATABASE. I'm of

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.