[python] Check in for the second day of study - Provide several regular expression examples


Event address: CSDN 21-day learning challenge

The biggest reason for learning is to get rid of mediocrity. One day early will bring more excitement to life; one day late will bring more troubles of mediocrity. Dear friends, if you:
want to systematically/in-depth study a certain technical knowledge point...
It is difficult to persist in learning alone, and you want to form a group to learn efficiently... You
want to write a blog but have no idea how to start, and you urgently need some writing to inject energy...
Love writing, and are willing to let yourself become Better people

Study diary

**
1. Learn knowledge points

Parse file name

Parse windows drive letter

Parse file format

Parse file path

2. Problems encountered in learning

The code is too ugly

3. Gains from learning

Various information about a string of characters can be obtained

4. Practical operation

Get the entire path of a file in a string.
The code is as follows:
QRegExp NewRegExtPath("[AZ][:]([/]|[\\])*.*([/]|[\\])");

explain:

1. [AZ][:] A field with uppercase letters A~Z followed by a colon. The starting format of the drive letter name.

2. ([/]|[\\])* is a folder path separator composed of multiple slashes and backslashes.

3. .*Characters of any length. process.

4. ([/]|[\\]) ends with a slash and a backslash.

It feels very buggy and not fully tested.

 

Get the file name in a string.
The code is as follows:
QRegExp NewRegExtName("[A-Za-z0-9_]*");

explain:

1. [A-Za-z0-9_]* A string composed of [A-Za-z0-9_] character locks of any length. The file naming stipulates that there cannot be special characters.

Get the suffix format of the file in a string. 
The code is as follows: 
QRegExp NewRegExtFormat("[A-Za-z0-9_]*[.]");

explain:

1. Same as above, but it is stipulated that it ends with.

This part is incomplete and has no creative ideas.

Reminder: Please delete unused content before publishing your work (please keep the event address)

Guess you like

Origin blog.csdn.net/qq_34217861/article/details/126123965