How to use regular matching to delete blank lines and comment lines in phpstorm

php中世界最好的语言
Release: 2023-03-26 21:58:01
Original
1799 people have browsed it

This time I will show you how to use regular matching to delete empty lines and comment lines in phpstorm. What are the precautions for using regular matching to delete empty lines and comment lines in phpstorm. The following is a practical case. Let’s take a look.

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 achieved. need.

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 uses regular expressions to delete PHP codeTips for empty lines

Many friends will encounter special empty lines of code There are many, but deleting rows one by one will definitely be annoying. At this time, you need to delete blank rows 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:

I believe you have mastered the method after reading the case in this article. Please pay attention for more exciting things. Other related articles on php Chinese website!

Recommended reading:

Summary of the steps to use commas and dots for echo in php

PHP development of WeChat remote control Detailed explanation of server steps

The above is the detailed content of How to use regular matching to delete blank lines and comment lines in phpstorm. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!