Home > front end >  Extract the required part from same type of URLs in notepad by regex
Extract the required part from same type of URLs in notepad by regex

Time:03-11

I have a list of URLs from same website. How can I extract a particular part of them using regex in Notepad ?

Here is a part of the URLs:

https://www.example.in/example/MT60B2G8HB-48BA-TR?qs=iLbezkQI%2BsgqYFd1yfooJw==
https://www.example.in/example/AT25L128A-MHE-T?qs=IS%2B4QmGtzzoXQyQfwYv36A==

Output should be MT60B2G8HB-48BA-TR & AT25L128A-MHE-T from all the similar type of URLs.

CodePudding user response:

If all URLs have the same url, path up until the last part & do always have GET-parameters (using ?), then you can use this:

"(?<=https://www.example.in/example/)[^?] "
# match any string that has https://www.example.in/example/ before it until the first ?

If it is optional whether the url has GET-params:

"(?<=https://www.example.in/example/)[^?\s] "
# match any string that has https://www.example.in/example/ before it until the first ? or whitespace/linebreak

CodePudding user response:

the following will allow you to search for the pattern (in regex mode of course) :

(?<=https://www.example.in/example/).*(?=\?)

(?<=...) is called positive lookbehind and must be a fixed pattern positioned before what you are looking for

(?=...) is called positive lookahead and must be a fixed pattern positioned after what you are looking for (here the first '?' escaped with '\')

If you want to replace the pattern then you can simplify to this.

Find what : https://www.example.in/example/(.*)\?.*
Replace with : $1

  • Related