I have a string that looks like this:
lonfksa.newsvine.com
and I have tons of file that looks like this:
http://ricambi.ru/avtomobilnie-novosti/lexus-gotovit-k-debiutu-obnovlenniy-rx
http://www.kiwibox.com/hoytboar/blog/entry/121424391/modis-tshirt-tips-untuk-womens-clothing/
http://www.euro-rockradio.com/archives/category/interview
http://lonfksa.newsvine.com/_news/2014/04/18/23538711-vampir-romantis-clothing
http://www.fam-hinterseer.de/cgi-bin/info.php?a%5B%5D=%3Ca+href%3Dhttp%3A%2F%2Fwww.shopious.com%3Ecart+means+payment%3C%2Fa%3E
http://www.kiwibox.com/donniehihp/blog/entry/116146741/skin-care-beauty-makeup-tips-for-female/
http://www.kiwibox.com/karlagbr/blog/archive/2014/9/7/
I wanted to match the line that contains:
lonfksa.newsvine.com
and I tried the following regex but it doesn't work:
(?s)lonfksa.newsvine.com(?s)
what regex should I use to match the whole line that has this string?
You can make use of the multiline flag, and ^ and $ anchors that will match at the string start and string end repsectively:
(?m)^.*lonfksa\.newsvine\.com.*$
Mind that you need to escape a dot in regex to make it match a literal dot. Your regex (?s)lonfksa.newsvine.com(?s) contains unescaped dots that match any character (even a newline since you are using a singleline inline option (?s)). The final inline option (?s) is not necessary, it does not do anything.
Try this regex :
^.*lonfksa\.newsvine\.com.*\b
Demo
Related
I need to cut lines that have 6 or more characters, hyphen, then other characters or symbols. Hyphen and rest of line should be removed. Source text:
0402CS-2
0402CS-3
0402
7812-C
0603CS-1
0603CS-2
0603CS-3
As a result, I need this:
0402CS
0402CS
0402
7812-C
0603CS
0603CS
0603CS
To do that, I use Notepad++ regexp replace feature. Find pattern: ^([^\-]{6,})\-.+$ Replace pattern: \1
But there is no option "multiline", so, symbols "^" and "$" doesn't match ONLY beginning and end of the line and actually I have result:
0402CS
0402CS
0402
7812 <-- that's wrong!
0603CS
0603CS
0603CS
Please advice me how to fix find pattern? Or, maybe there is other handful and powerful free text editor that can do that?
^([^\n\-]{6,})\-.+$
^^
Just use \n as due to [^-] the regex can traverse to line below as use that line to make a match.
See demo.
https://regex101.com/r/BHO93c/1
for the input
0402
7812-C the regex matches both lines as 1 line and makes a match.
See demo if 0402 is not there.
https://regex101.com/r/BHO93c/2
That happens because the [^-] character class also matches a newline.
Add \n to it:
^([^\n-]{6,})-.+$
See the regex online demo (note the m multiline modifier (making ^ match the start of the line, and $ - the end of the line) and g modifier (enabling search for multiple occurrences) that is ON by default in Notepad++).
Note that escaping the hyphen is not necessary inside a character class when it is at the start/end of the class, and you never need to escape the hyphen outside the character class.
I'm trying to replace whitespaces with underscores in certain parts of my html-document with Notepad++.
I can identify the area to search for the whitespaces in the following way:
-Begins with: src="video/
-Ends with: mp4
For example I might have a line like this:
<video class="play" src="video/my file name with empty spaces.mp4">
and I would like to change it to be like this:
<video class="play" src="video/my_file_name_with_empty_spaces.mp4">
Tested in N++
Search: (?:src="video|(?<!^)\G)(?:(?!mp4).)*?\K\s+
Replace: _
On the demo, see the substitutions at the bottom.
Explanation
(?:src="video|(?<!^)\G) matches the delimiter src="video, or \G the position following the previous match as long as it is not at the beginning of the string (?<!^) where \G can also match
(?:(?!mp4).) matches one character that is not followed by mp4
*? lazily matches such characters, up to...
\s a space character (our match which we replace with _)
before the space, the \K tells the engine to drop what was matched so far from the final match it returns
I'm so close to understanding regex. I'm a bit stumped, I thought i understood lazy and greedy.
Here is my current regex: <g_n><!\[CDATA\[([^]]+)(?=]]><\/g_n>)
My current regex makes:
<g_n><![CDATA[xxxxxxxxxx]]></g_n>
match to:
<g_n><![CDATA[xxxxxxxxxx
But I want to make it match like this:
xxxxxxxxxx
You want
<g_n><!\[CDATA\[(.*?)]]></g_n>
then if you want to replace it use
\1
in the replacement box
Your matching the whole string, the brackets around the .*? match all of that and put it in the \1 variable
So the match will be all of the string with \1 referring to what you want
To change the xxxxx
Regex :
(<g_n><![CDATA[)(?:.*?)(]]></g_n>)
Replacement
\1WHAT YOU WANT TO CHANGE TO\2
It looks like you need to add escape slashes to the two closing square brackets, as they are literals from the string you're parsing.
<g_n><!\[CDATA\[.*+?\]\]><\/g_n>
^ ^
Any square brackets not being escaped by backslashes will be treated as regex operational brackets, which in this case won't catch the input string.
EDIT, I think the +? is redundant.
\[.*\]\]> ...
should suffice, since .* means any character, any amount of times.
Tested with notepad++ 6.3.2:
find: (<g_n><!\[CDATA\[)([^]]+)(?=]]></g_n>)
replace: $1WhatYouWant
You can replace + by * in the pattern to match void CDATA:
<g_n><![CDATA[]]></g_n>
Is there a way to match any character in Sublime Text, including newlines? I saw that Sublime uses Boost's syntax but that the . character won't match newlines without a specific flag set.
Try adding the (?s) inline flag start the start of the pattern. That will make . match any character.
I havin a reg ex problemm i would like to have a reg ex that will match the '\nGO at the end of my file(see below.) I have got the following so far:
^\'*GO
but its match the quote sysbol?
EOF:
WHERE (dbo.Property.Archived <> 1)
'
GO
In Perl \Z matches the end of the string, totally ignoring line breaks. Use this to match GO on the last line of a file if the file is loaded into a string:
^GO\Z
POSIX regex uses \' instead of \Z.
To match exactly the newline and then the word GO in your example, you want this:
\nGO
You can also do this:
\n.*GO
This last regular expression will match what you want in your example, but the .* part will make it so there can be anything (or nothing) in between the newline and GO.