Home > Backend Development > PHP Tutorial > phpstorm regular matching to delete empty line comment lines tips sharing

phpstorm regular matching to delete empty line comment lines tips sharing

小云云
Release: 2023-03-19 15:52:02
Original
1994 people have browsed it

It feels good to use phpstorm to write php and javascript codes, and it is very comfortable to use. This article mainly introduces phpstorm regular matching to delete blank lines and comment lines. Friends who need it can refer to it. I hope it can help everyone.

I encountered a need. Sometimes when reading the source code of a framework, I want to filter (delete) the comment lines in the source code. If I delete it manually line by line, it will not be scientific enough.

Of course, I thought of the powerful regular expression (regExp regular expression). By writing a regular expression, we can find all the comment lines and replace them with empty ones, which is how we achieve the requirement.

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

2. ctrl + R, do not enter:

3. Click Replace all

but found that this did not fully realize our needs, but only replaced 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 the regular expression: ^n

2.ctrl + R, do not enter

3. Click the following Replace all

But I found that not all blank lines were deleted. (There are still some blank lines that have not been deleted)

So, let’s continue with a regular matching deletion.

1.ctrl + F, enter the regular expression: sn

2.ctrl + R, do not enter

3. Click Replace at the end all

Okay, here, delete all the blank lines. Have fun -:)

Tips for using phpstorm to delete blank lines in PHP code using regular expressions

Many friends will encounter a lot of blank lines in the code, but they delete them one by one. It must be very irritating. At this time, you need to delete blank lines in batches.

How to delete blank lines in batches?

My method is to use regular expressions to find all blank lines, and then replace them all with one click.

First check Match Case and Regex

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

Match all blank lines After that, click [Replace all].

The replacement effect is as follows:

In fact, these three steps should be implemented in one step. You can think about it think!

Related recommendations:

Detailed explanation of some regular matching expressions in jQuery

php regular matching remote image address in the article and downloading Detailed explanation of how to transfer images to local instances

Detailed explanation of the method of matching Chinese characters with php and javascript

The above is the detailed content of phpstorm regular matching to delete empty line comment lines tips sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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