Get the App
SLTechnology News&Howtos  ›  Development  › 

Delete blank lines and comment lines using phpstorm regular matching

Shulou Source: shulou.com Published: 2022-06-03 19:54:42 10月04日 Update

This article mainly introduces "delete blank lines and comment lines using phpstorm regular matching". In daily operation, I believe many people have doubts about deleting blank lines and comment lines using phpstorm regular matching. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "delete blank lines and comment lines using phpstorm regular matching". Next, please follow the editor to study!

Encountered a requirement, sometimes when reading the framework source code, want to filter (delete) the comment lines in the source code, if the manual line-by-line deletion display is not scientific.

Of course, think of the powerful regular matching (regExp regular expression), by writing a regular expression to find all the comment lines and replace them with empty, that is, the requirements are implemented.

1. Ctrl + F, enter the regular expression: (/ /. * $) | (/ * (. | s) *? * /)

2. Ctrl + R, do not enter:

3. Click the Replace all at the back

However, it turns out that this does not fully implement our requirements, but simply replaces the comment line with a blank line.

So, let's write another regular expression to match the blank lines and delete them.

1.ctrl + F, enter regular expression: ^ n

2.ctrl + R, do not enter

3. Click the Replace all at the back

However, it is found that the blank lines have not been deleted. (some blank lines have not been deleted)

So, let's move on to a regular matching deletion.

1.ctrl + F, enter regular expression: sn

2.ctrl + R, do not enter

3. Click the Replace all at the back

OK, at this point, all blank lines are deleted. Have fun -:)

Tips for phpstorm to regularly delete blank lines from PHP code

Many friends will encounter a lot of blank lines of code, but it must be annoying to delete a line, so you need to delete blank lines in bulk.

How to delete blank lines in batches?

My way is to find all the blank lines with the rule and replace them all with one click.

First, tick Match Case and Regex

Fill in the regular rule in the first search box: ^\ n

After matching all the blank lines, click [Replace all].

The replacement effect is as follows:

In fact, these three steps should be realized in one step, you can think about it!

At this point, the study on "using phpstorm regular matching to delete blank lines and comment lines" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Blank lines rules comments input expressions learning requirements one line code more source code help practical powerful irritable and then not enough way just boy Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Apple MySQL Huawei Linux