Reputation: 65
I have a text file in Notepad++ with the following structure:
"description": "",
"devtoolsFrontendUrl": "https://randomurl",
"id": "39004",
"title": "RandomTitle",
"type": "page",
"url": "https://www.randomurl",
"webSocketDebuggerUrl": "randomurl"
Wherever it says randomurl
there is a different URL address.
This structure is repeated in my document a couple thousand times. (however the information of "title, url" etc. is different for each.)
What I'd like to do is filter out (from each structure) only the following information:
"title": "RandomTitle"
"url": "https://www.randomurl"
The rest can be deleted. How would I go about doing that with Regex? (I assume)
Upvotes: 2
Views: 1258
Reputation: 14047
There is more than one way to achieve this. @Toto gives a way using regular expression. Another way uses Bookmarking.
Using the "Mark" tab of the search panel (or menu => Search => Mark). Enter ^"(title|url)":
into the search parameters, ensure "Bookmark lines" is selected, and click on Mark All. Expect to see blue blobs at the left of the marked lines. Now use menu => Search => Bookmark => Remove unmarked lines. Alternatively, could use menu => Search => Bookmark => Copy bookmarked lines and paste them elsewhere (even into another application).
The Mark All step could be split into two steps. This style might be useful if more complex searching is needed. Proceed as above but enter ^"title":
into the "Find what" field, then click on Mark All. Note that the "title" lines have blue blobs. Next enter ^"url":
into the "Find what" field, ensure that "Purge for each search" is not selected, then click on Mark All. Note that now both "title" and "url" lines have blue blobs. As above, can now do a Remove unmarked lines or Copy bookmarked lines.
Upvotes: 2
Reputation: 91428
^.*"(?:title|url)".*\R(*SKIP)(*FAIL)|[\s\S]
LEAVE EMPTY
. matches newline
Explanation:
^ # beginning of line
.* # 0 or more any character but newline
(?: # non capture group
title # literally
| # OR
url # literally
) # end group
" # quote
.* # 0 or more any character but newline
\R # any kind of linebreak
(*SKIP) # skip this match
(*FAIL) # and consider match has failed
| # OR
[\s\S] # any character
Screenshot (before):
Screenshot (after):
Upvotes: 2