简体   繁体   中英

Sublime Text Editor Regex (Find & Replace - Add Prefix and Postfix)

I'm facing an issue where I have a list of website addresses like following:

http://xsi82.com
http://xsi122.com/view/8383.html
http://sdf242.com/view/4483.html
http://oudi38.com/view/182483.html
https://83jsla.com/forum/view1234.html
https://hello192.com/page/hello.html
http://hsl1092.in/world

There are like 2000+ URLs.

I want to basically extract out the domains and put them on a ban list in .htaccess

I want to remove everything that is after .com and I want to remove everything that is in the prefix like http:// or https:// or http://www. or ' https://www .' and sometimes some websites are like www23. or any other sub-domain.

Once that is done and I get a clean list, I need to add

RewriteCond %{HTTP_REFERER} ^http(s)?://(.+.)?

in the prefix of the line and

/ [NC,OR]

at the end.

The end result of would look something like:

 RewriteCond %{HTTP_REFERER} ^http(s)?://(.+.)?xsi82\.com/ [NC,OR]

you can use this ((\\w+\\.\\w+)(?=\\/))|((?<=\\.)|(?<=\\/\\/))((\\w+\\.\\w+)\\n)

In this way, you do not need to delete before and after the domain
you just need to extract the domain from the heart of url

Online demo


If you want to delete everything except the domain:

  1. remove everything before domain: (.+(?|(?>\\/\\/.\\.)|(?>\\/\\/)|(?>(ww.)\\.))) Demo
  2. remove everything after domain: (?<=\\w)(\\/.+) Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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