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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:39:46+00:00 2026-06-07T10:39:46+00:00

When user passes a directory name to my program, i check it against private

  • 0

When user passes a directory name to my program, i check it against

private static final Pattern    DIRECTORY_PATTERN   
            = Pattern.compile("/*?([a-zA-Z_0-9]+)/*?",
                    Pattern.CASE_INSENSITIVE);

For what we’ve seen so far, this works, but i suspect this regex is incomplete.

Do you know of, or can you suggest a more complete regex, which would validate directory name?

  • 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-07T10:39:47+00:00Added an answer on June 7, 2026 at 10:39 am

    Actually, there are a great many more characters you can use in a file name, even heinous things like backspaces and newline characters. In fact, you may find it depends on the underlying file system. I vaguely remember a rule somewhere that allowed everything except the actual path separator.

    One thing I always consider when deciding if something is valid is to use it. For example, you can validate the format of an email address with a (complex) regex but the only way to be certain it’s fully valid is to send a hyperlink mail to it to verify it’s received.

    In your particular case, if you want to create a file with that name, you can try to create a temporary file, in a directory you’re actually allowed to create files in. If the file is created successfully, you can be pretty sure it’s a valid name 🙂 Of course, if you’re creating a file, you may just want to create the real file. If you’re opening an existing file, forget the regex, just try to open the file – no amount of complication in your regex will tell you if the file exists or is readable by you.

    To be frank, though, I’d consider placing your own limitations on the allowed characters – I have, in the past, cursed people who were silly enough to create file names with CTRL characters in them, or one called -rf that the rm command had troubles with (until you figure out how to get around that).

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

Sidebar

Related Questions

User first_name: Johnny age: 15 Car name: Mazda Car name: BMW I would like
User Defined Function (UDFs) are functions that one can program and can be dynamically
In my function user inputs a path like './images/profile' and i need to check
I have the following scenario- Pig version used 0.70 Sample HDFS directory structure: /user/training/test/20100810/<data
I am calling CreateFile() to create a file in the Program Data directory. I'm
Is there any way to show user popup to give the name to create
I have a mathparser that can do functions like IntPow(3,2). If a user pastes
I'd like to search a MySQL database to match keywords passed by the user.
I cannot remember where, but recently I passed a comment where the user told
User Story: Action for Facebook that has open graph object. For this I need

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.