Phpstorm regular match deletes empty lines, comment lines (replace empty lines with empty lines), and phpstorm empty lines

Source: Internet
Author: User

Phpstorm regular match deletes empty lines, comment lines (replace empty lines with empty lines), and phpstorm empty lines

Phpstorm is used to compile php and javascript code. It feels good and comfortable to use.

Sometimes, when reading the source code of the framework, you may want to filter (delete) Comment lines in the source code. It is not scientific to manually delete lines by line.

Of course, we thought of a powerful regExp regular expression. by writing a regular expression, we can find all the comment rows and replace them with null to meet our needs.

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

2. ctrl + R, without entering:

3. Click Replace all.

However, we found that this did not fully implement our needs, but simply replaced the comment line with a blank line.

Therefore, let's write another regular expression to match and delete empty rows.

1. Press ctrl + F and enter the regular expression:^n

2. ctrl + R, do not enter

3. Click Replace all.

However, it was found that empty rows were not all deleted. (Some blank lines are not deleted)

Therefore, we will continue to delete a regular expression matching.

1. Press ctrl + F and enter the regular expression:sn

2. ctrl + R, do not enter

3. Click Replace all.

Okay. Here, all empty rows are deleted. Have fun -:)

Tips for using regular expressions to delete empty PHP code in phpstorm

Many friends may encounter a lot of empty lines in the code, but it is annoying to delete one line and one line. In this case, batch Delete empty lines is required.

How can I batch Delete empty rows?

My solution is to use regular expressions to locate all blank rows and replace them with one click.

First, check the Match Case and Regex.

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

After all blank rows are matched, click Replace all.

The replacement effect is as follows:

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.