Home > Java > How to parse filename formats such as 'PUBLIC001' using regular expressions?

How to parse filename formats such as 'PUBLIC001' using regular expressions?

WBOY
Release: 2024-02-11 21:57:08
forward
1047 people have browsed it

In this article, php editor Zimo will introduce how to use regular expressions to parse file names named in formats such as "PUBLIC001". Regular expressions are a powerful text matching tool that can be used to extract required information quickly and accurately. For this specific file name format, we can extract the numeric part through appropriate regular expressions to achieve parsing purposes. Next, let's explore how to use regular expressions to parse this file name format!

Question content

Need help with regular expressions for parsing file names

The file will be named PUBLIC001 "PUBLIC" is static text in all filenames Last 3 digits - day of the year. 001 (Jan 1)-366 (December 31 of leap year) is the valid range

What is a regular expression. Is there a way to limit the maximum value to 366?

Thank you

Solution

Similar patterns:

public([0-2]\d\d|3[0-5]\d|36[0-6])
Copy after login

Will do.

Or, if verifying the date number is not important, something like:

public\d\d\d
Copy after login

or

public\d{3}
Copy after login

I will do the same.

If the file should not have any other parts, add ^ and $ at the beginning and end respectively (this will avoid matching not-public001 for example or public001002)

like:

^PUBLIC\d{3}$
Copy after login

The above is the detailed content of How to parse filename formats such as 'PUBLIC001' using regular expressions?. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template