Home > Backend Development > PHP Tutorial > phpstorm regular matching deletes blank lines and comment lines

phpstorm regular matching deletes blank lines and comment lines

jacklove
Release: 2023-04-02 07:12:02
Original
2319 people have browsed it

This article mainly introduces phpstorm's regular matching to delete blank lines and comment lines. Friends who need it can refer to it

Using phpstorm to write php and javascript codes, it feels good and is very comfortable to use. .

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 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 all# at the end

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


phpstorm tips for using regular expressions to delete empty lines in PHP code

Many friends will encounter code There are a lot of blank lines, but deleting them one by one is definitely annoying. 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!

Articles you may be interested in:

Parsing Laravel dependency injection related content through source code

Examples of sequential linked lists and linked linear lists of php data structure

Detailed explanation based on the difference between using commas and dots for echo in php

The above is the detailed content of phpstorm regular matching deletes blank lines and comment lines. 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