本篇文章给大家带来的内容是关于NotePad++正则表达式如何进行替换(图文),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
NotePad++ 正则表达式替换 高级用法
const getQAPartnerSites = (params) => wxRequest(params, apiUrlApp + 'ask/show_sites/') const getQARecommender = (params) => wxRequest(params, apiUrlApp + 'ask/question_likely/') const postQAurls = (params) => wxRequest(params, apiUrlApp + 'ad/ad_pub/') const getQAPublished = (params) => wxRequest(params, apiUrlApp + 'ask/ask_list/')
^const\W{1}(\w+)\W{1}\={1}.+$ \1,
getQAPartnerSites, getQARecommender, postQAurls, getQAPublished,
在我们处理文件时,很多时候会用到查找与替换。当我们想将文件中某一部分替换替换文件中另一部分时,怎么办呢? 下面正则表达式 给我提供方法。
正则表达式,提供复杂 并且弹性的查找与替换
注意: 不支持多行表达式 (involving \n, \r, etc).
1 基本表达式
符号 | 解释 |
---|---|
. | 匹配任意字符,除了新一行(\n)。也就是说 “.”可以匹配 \r ,当文件中同时含有\r and \n时,会引起混乱。要匹配所有的字符,使用\s\S。 |
(…) | 这个匹配一个标签区域. 这个标签可以被访问,通过语法 \1访问第一个标签, \2 访问第二个, 同理 \3 \4 … \9。 这些标签可以用在当前正则表达式中,或则替search和replace中的换字符串。 |
\1, \2, etc | 在替换中代表1到9的标签区域(\1 to \9)。例如, 查找字符串 Fred([1-9])XXX 并替换为字符串 Sam\1YYY的方法,当在文件中找到Fred2XXX的字符串时,会替换为Sam2YYY。注意: 只有9个区域能使用,所以我们在使用时很安全,像\10\2 表示区域1和文本”0”以及区域2。 |
[…] | 表示一个字符集合, 例如 [abc]表示任意字符 a, b or c.我们也可以使用范围例如[a-z] 表示所以的小写字母。 |
[^…] | 表示字符补集. 例如, [^A-Za-z] 表示任意字符除了字母表。 |
^ | 匹配一行的开始(除非在集合中, 如下). |
$ | 匹配行尾. |
* | 匹配0或多次, 例如 Sa*m 匹配 Sm, Sam, Saam, Saaam 等等. |
+ | 匹配1次或多次,例如 Sa+m 匹配 Sam, Saam, Saaam 等等. |
? | 匹配0或者1次, 例如 Sa?m 匹配 Sm, Sam. |
{n} | 匹配确定的 n 次.例如, ‘Sa{2}m’ 匹配 Saam. |
{m,n} | 匹配至少m次,至多n次(如果n缺失,则任意次数).例如, ‘Sa{2,3}m’ 匹配 Saam or Saaam. ‘Sa{2,}m’ 与 ‘Saa+m’相同 |
*?, +?, ??, {n,m}? | 非贪心匹配,匹配第一个有效的匹配,通常 ‘<.>’ 会匹配整个 ‘content’字符串 –但 ‘<.>’ 只匹配 ” .这个标记一个标签区域,这些区域可以用语法\1 \2 等访问多个对应1-9区域。 |
2 标记和分组
符号 | 解释 |
---|---|
(…) | 一组捕获. 可以通过\1 访问第一个组, \2 访问第二个. |
(?:…) | 非捕获组. |
(?=…) | 非捕获组 – 向前断言. 例如’(.*)(?=ton)’ 表达式,当 遇到’Appleton’字符串时,会匹配为’Apple’. |
(? | 非捕获组 – 向后断言. 例如’(? |
(?!…) | 非捕获组 – 消极的向前断言. 例如’.(?!e)’ 表达式,当遇到’Apple’时,会找到每个字母除了 ‘l’,因为它紧跟着 ‘e’. |
(? | 非捕获组 – 消极向后断言. 例如 ‘(? |
(?P…) | 命名所捕获的组. 提交一个名称到组中供后续使用,例如’(?PA[^\s]+)\s(?P=first)’ 会找到 ‘Apple Apple’. 类似的 ‘(A[^\s]+)\s\1’ 使用组名而不是数字. |
(?=name) | 匹配名为name的组. (?P…). |
(?#comment) | 批注 –括号中的内容在匹配时将被忽略。 |
3 Special symbols
Symbol | Explanation |
---|---|
\s | Matches spaces. Note that the end of the tag will be matched. Use [[:blank:]] to avoid matching new lines. |
\S | Matches non-whitespace |
\w | Matches word characters |
\W | Matches non-word characters |
\d | Matches numeric characters |
\D | Match non-numeric characters |
\b | Match word boundaries. '\bW\w ' Find words starting with W |
\B | Matches non-word boundaries. '\Be\B ' – Finds the letter 'e' in the middle of a monad |
\ | This matches the start of a word using Scintilla's definitions of words. |
> | This matches the end of a word using Scintilla's definition of words. |
\x | runs using x to express characters that may have other meanings. For example, [ is used to insert into text as [ rather than as the beginning of a character set. |
4 Character Classes
Symbol | Explanation |
---|---|
Match alphabetical characters: [A-Za- z] | |
Matches numeric characters: [0-9] | |
Matches hexadecimal characters: [0-9A-Fa-f] | |
Match alphanumeric characters: [0-9A-Za-z] | |
Match lowercase characters: [a-z] | |
Matches uppercase characters: [A-Z] | |
Match white space (space or tab):[ \t] | |
Match white space characters:[ \t\r \n\v\f] | |
Matches punctuation characters: [-!”#$%&'()* ,. /:;?@[]_`{ | |
Match graphic characters: [\x21-\x7E ] | |
Matches printable characters (graphical characters and spaces) | |
Match control characters |
Search string | Replace string | Result | |
---|---|---|---|
my name is (. ) | my name is not \1 | Hi my name is not Fred | ##The quick brown fox jumped over the fat lazy dog |
brown \2 jumped over the \1 | The quick brown fat jumped over the fox lazy dog |
The above is the detailed content of How to replace regular expressions in NotePad++ (picture and text). For more information, please follow other related articles on the PHP Chinese website!

Installation steps of Notepad: 1. Visit the official website to download the latest stable version; 2. Run the installation file and click "Next"; 3. Agree to the license agreement; 4. Select the installation path; 5. Select whether to create a desktop shortcut and start menu folder; 6. Complete the installation and start Notepad.

Notepad is free and open source, and is licensed under the GPLv2. 1. Anyone can use and modify Notepad for free. 2. When used by the enterprise, any modification or extension must be published in GPLv2. 3. The use of commercial products must comply with GPLv2, including public source code.

Notepad originatesfromFrance,createdbyDonHo.1)France'sfocusoneducationandtechnologyfostersinnovation,reflectedinNotepad 'sdesign.2)Theopen-sourceethosalignswithFrenchvaluesofsharingknowledge.3)EfficiencyandperformancearehallmarksofFrenchengineering

Notepad sustainsitselffinanciallythroughdonations,sponsorships,andapluginecosystem.1)Donationsfromusersprovidethemainincome,keepingthetoolfreeandfosteringcommunity.2)Sponsorshipsfromcompaniesofferastableincomewhilemaintainingindependence.3)Apluginec

Free alternatives to Notepad include VisualStudioCode, SublimeText, and Atom. 1. VisualStudioCode supports multiple languages and enhances features through extensions. 2. SublimeText provides an evaluation version, which is fast and has a simple interface. 3.Atom is known for its high customizability and is suitable for personalized needs.

Notepad is a free and open source text editor. 1) Free use lowers the entry threshold, 2) Open source features are implemented through the GPLv2 license, allowing the viewing, modifying and distributing source code, promoting community participation and software evolution.

Notepad is a free text editor for Windows, which offers a variety of features such as: 1) syntax highlighting, 2) autocomplete, 3) macro recording, 4) plug-in extensions, 5) customizable interfaces and settings.

Notepad itself does not have automatic layout function. We can use a third-party text editor, such as Sublime Text, to perform the following steps to achieve automatic typography: 1. Install and open the text editor. 2. Open the file that needs to be automatically typed. 3. Find and select the automatic layout function. 4. The editor will automatically type the text. 5. You can customize the layout rules as needed. Automatic typography can save time and ensure text consistency and professionalism.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools