How to extract specific length urls from text file using Notepad++

1

I am trying to extract the list of URLs from the text file using notepad++ and have tried different expressions as well, but it is replacing the URLs instead of extracting them.

href="https://prnt.sc/2oz4yt" class="external-link" rel="nofollow noreferrer">https://prnt.sc/4om4fj</a></p>
    <br/>
    <br/>

I have large text file like mixture content inside it but I want to extract only prnt.sc list from it

https://prnt.sc/2oz4yt
https://prnt.sc/4om4fj

how to achieve this?

Mr.Devops

Posted 2020-01-30T10:04:22.537

Reputation: 13

Interesting... the ampersands are valid parts of URLs but are obviously junk in this case. You might need to run a Find/Replace on those first before trying any regex. – Burgi – 2020-01-30T10:33:33.257

yes, whatever the best solution, waiting for the answer! i have more than 250 prnt.sc URLs in 1 file contain same mixture of tags from where i want to extract the specific domain URL with specific length! – Mr.Devops – 2020-01-30T10:37:35.453

Answers

2

  • Ctrl+H
  • Find what: \G(?:(?!https://prnt.sc/\w{6}).)*(https://prnt.sc/\w{6})?
  • Replace with: (?1$1\n)
  • CHECK Match case
  • CHECK Wrap around
  • CHECK Regular expression
  • CHECK . matches newline
  • Replace all

Explanation:

\G                      # restart from last match position
(?:                     # non capture group
  (?!                   # negative lookahead, make we haven't after:
    https://prnt.sc/      # literally
    \w{6}                 # 6 word characters
  )                     # end lokkahead
  .                     # any character
)*                      # end group may appear 0 or more times
(                       # group 1
    https://prnt.sc/      # literally
    \w{6}                 # 6 word characters
)?                      # end group, optional

Replacement:

(?1         # if group 1 exists
  $1        # keep it
  \n        # line break, you could use \r\n for windows end of line
)           # end condition

Screen capture (before):

enter image description here

Screen capture (after):

enter image description here

Toto

Posted 2020-01-30T10:04:22.537

Reputation: 7 722

Awesome! just solved my problem by using your suggestion and 1 change is by deselecting .matches newline. – Mr.Devops – 2020-01-30T11:29:08.067

@Raza: You're welcome, glad it helps. – Toto – 2020-01-30T11:32:04.693