How to find specific string (in my case its a link) that end with quotation mark.
-
In my file i have only 10 lines, like that
https://imgur.com/s7JCMfPMaybe bacause of that i cant achive what i want.
After Find and replace
https://imgur.com/ESaV0VU
it deletes almost everything i need and leaves me with 8 matches of twitch.Like this
https://imgur.com/SGHI8W2Here is a txt file that i am using , maybe this way it will be easier to figure out.
http://rgho.st/6TlbcFmlG -
@Fujosej-Fujo
Your file was a great help. Definitely needed to see that as it showed me that the lines were very long, with multiple occurences on each line of the text you want.So here is my revised set of steps.
- Make a copy in another tab of Notepad++
- Use the Replace Function to remove all line endings (carriage return line feeds).
Find What:\R
Replace with:empty field
<—nothing in this field
Now everything is on 1 line (it may not look that way if you have word wrap turned on)
- Use Replace function to remove ALL unwanted text.
Find What:.+?(https://www.twitch.tv/[^"]+)
Replace With:\1
This will remove all unwanted text except for the last occurance.
- Now to put all occurances of the text we want on different lines.
Find What:(https://www.twitch.tv/)
Replace With:\r\n\1
Once this step is completed, go to the last line and remove the extra text behind the portion you want to keep.
Again this is a quick process, I haven’t spent much time on making it do everything. Sometimes quick and easy steps are better than trying to cover ALL bases and using a long winded approach.
Have a go and let us know.
Terry
-
@Fujosej-Fujo
I have had a slightly longer look at the file you provided. I note that you mentioned about quotes, however your initial regex did NOT include those. In the file it would appear there are some instances of twitch.tv without quotes. I’m not sure you actually intend to capture those as well.I’ve made a revised regex which doesn’t need so many steps, however it will still require the final file to be edited a bit. Once you try it you will see what I mean. Some of the lines stick out very easily as not being correct.
Find What:
.+?"(https://www.twitch.tv/[^"]+)
Replace With:\1\r\n
So no need to remove carriage returns, but you will need to remove those lines that DON’T start with “https”. This can be done with Mark, also ticking bookmark, which can then be used to remove lines bookmarked.
Find What:^[^h]
Terry
-
This is amazing, thank you very much , works beautifully.
-
Hello @fujosej Fujo, @rerry-r and All,
Thanks, @fujosej-fujo, for your
new 6.txt
text file. It’s always better to work on “real” data ;-))I think, @terry-r, that all work can be reduced to an unique, regex S/R, only ;-))
So, @fujosej-fujo, basically, you’re searching for any area of text :
-
Beginning with
"https://www.twitch.tv
-
Ending at the first next quote char
"
This regex, which searches for such an area, is :
(?s-i)"https://www.twitch.tv.+?"
Notes :
-
The
(?s-i)
modifiers, at beginning, means that :-
Any meta-character dot (
.
) represents, absolutely, any single character, even EOL ones ((?s)
) -
The regex engine will search in a non-insensitive way (
(?-i)
)
-
-
Then, it searches the literal string
"https://www.twitch.tv
-
Finally the part
.+?"
finds the shortest area of any character, till the first next quote char"
Now that we built this first regex to match the zones to extract, we create a second regex which contains this first regex, using the syntax, where your regex is surrounded with parentheses, in order to store its value as group
1
, for future replacement :SEARCH
(?s-i).+?(
Your regex)|.+
Thus, this leads to the correct regex S/R, below :
SEARCH
(?s-i).+?("https://www.twitch.tv.+?")|.+
REPLACE
\1\r\n
=> From your
new 6.txt
file,366
replacements occur and you get a neat list of365
links ;-))Notes :
-
After the modifiers, the part
.+?
matches the shortest part from, either, the beginning of file or the end of the previous match, until the expression"https://www.twitch.tv.+?"
-
In replacement, we rewrite, only, the expected group
1
, which must be extracted, followed with a line-break -
Near the end of the file, when no more
"https://www.twitch.tv
can be found, the regex engine uses the second alternative.+
, after the alternation symbol|
, which will grab all text till the very end of the file, as the(?s)
modifier is always active ! -
This time, as group
1
is not defined, the replacement simply delete this last non-wanted part
Refer also to this more complete post, on that topic ( How to extract all the results matched ) :
https://notepad-plus-plus.org/community/topic/12710/marked-text-manipulation/8
Best Regards,
guy038
-
-
@guy038
You’re mostly correct, except that I believe the OP didn’t want the quote characters included, they were just to delimit the text he DID want. Thus your regex should be
Find What:(?s-i).+?"(https://www.twitch.tv.+?)"|.+
the Replace With field is as stated.Terry
-
Once again , thank you guys! Works like a charm.
-
I have one more question , sorry)
so lets say i have this list
http://rgho.st/6k9G4rHSh
i wanna add ‘s’ to http and also a ‘www.’ before twitch.
Is there a way to do this with regex? -
@Fujosej-Fujo
this is actually very easy. You only need to search forhttp://
and have the replacement ashttps://www.
.
You could even do this with the Replace function set to “normal” mode as there aren’t any special characters as used previously (.+?) etc.Find What:
http://
Replace With:https://www.
As I said this can be either as normal mode or regular expression mode, it won’t matter.
Terry
-
Thank you very much.That was easier than i thought.