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 RegexFill in the regular rules in the first search box:^\n
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!