简体   繁体   English

在记事本中用正则表达式替换文本

[英]Replace a text with regular expression in notepad++

I want to replace all the url's which are starting with something like www.sitename.com/xxx/xxx.html and the last part of the string is different on each url. 我想替换所有以www.sitename.com/xxx/xxx.html之类的开头的URL,并且字符串的最后一部分在每个URL上都不同。 Is there any formula in notepad++ which replace the whole string with "#" or any custom character ? notepad ++中是否有任何公式可以将整个字符串替换为"#"或任何自定义字符?

Bring on the Find and Replace dialog, select Replace ( Ctrl+H ) 进入“ Find and Replace对话框,选择“ ReplaceCtrl+H

Search mode: Regular expression 搜索方式: Regular expression

Find what: www\\.sitename\\.com/\\w+/\\w+\\.html 查找内容: www\\.sitename\\.com/\\w+/\\w+\\.html

Replace with: # (or anything you wish) 替换为: # (或您希望的任何内容)

This will replace URLs of the type you've provided in question ( www.sitename.com/xxx/xxx.html ) 这将替换您所提供的类型的URL( www.sitename.com/xxx/xxx.html

Press Ctrl+H to bring up the replace window. 按Ctrl + H弹出替换窗口。 Enter this in the Find what: section: 在“ Find what:部分中输入以下内容:

www\.sitename\.com(/\w+)*\.?\w*

and anything you want (#) in the Replace with: . 以及您要Replace with:所有内容(#) Replace with: Make sure that Search Mode is on Regulare Expression and the hit the Find next , Replace or Replace All 确保“ Search Mode位于正Regulare Expression ,然后单击“ Find next ,“ Replace或“ Replace All

This will replace all the URLs beginning with www.sitename.com and ending with and extension (.html, .jpg, ...) 这将替换所有以www.sitename.com开头并以和扩展名(.html,.jpg等)结尾的URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM