I have to edit a lot of source codes similar to each other.
random blah
random blah
blah
<table style="width: 232px; font-size: small;" cellpadding="0" cellspacing="0">....
What I want to do is to delete lines until table tag. I think I can do it with Regex search but I couldnt write the regex pattern.
Thank you
You have to go through multiple steps to do what you stated above:
Go to the replace window, select the "extended" mode, and in the "find what" field type in "\r\n" and replace them with: "LINEBREAK" (theres a space after 'LINEBREAK'). Click on replace all.
Go to the replace window again, select the "regular expression" mode, and in the "find what" field type in "(.*)(.*)(<table)(.*)(>)(.*)(.*)" and in the replace with field, type in "\2\3\4\5". Click on replace all.
Now go to replace window again, select elect the "extended" mode, and in the "find what" field type in "LINEBREAK" (theres a space after 'LINEBREAK') and replace them with: "\r\n". Click on replace all.
Notepad++ doesn't support multi line regex, which makes it hard to do what you wanted to do without going through the steps given above.
you can try something like:
(^.*$\n)*<table(.+)>
First group will match all lines before your table tag %)
Related
<span style='mso-tab-count:1'> </span>
<span style='mso-tab-count:1'> </span>
The bottom line above is from a "View Source Code" page and the top line is from the Chrome Developer Tools Source view. The RegEx below matches the bottom tags, which contain a series of spaces, but not the top tags, which enclose just empty whitespace. See this on the Regex Tester at https://regex101.com/r/P9dUP9/2
(<span style='mso-tab-count:1'>)\s{2,}(<\/span>)
How could I make the Regex also match the top line, and how can I tell the difference between the two kinds of whitespace on the screen without copying and pasting both of them into a text editor?
I guess it's a non-printable control character. My hex editor tells me it's \x20, but that's not captured for me. Your best bet would be using an exclusion such as:
(<span style='mso-tab-count:1'>)[^<]{2,}(<\/span>)
or
(<span style='mso-tab-count:1'>)\W{2,}(<\/span>)
I want to find this:
<p>
various text and code
</p>
...and replace it with completely different text. Atom doesn't seem to have a multi-line RegEx flag. How can I accomplish this?
The regular expression (.|\r?\n)*? is what you're looking for.
Used in the example above, <p>(.|\r?\n)*?</p> will select all three lines and you can then either replace or delete those lines.
Try the regex [\s\S]*?, with your example <p>[\s\S]*?</p>
see also https://github.com/atom/find-and-replace/issues/303
I have this sample, because is one of one million rows with that.
I have this text:
<tr class="even">
<td><a href="http://www.ujk.edu.pl/">Jan Kochanowski
University of Humanities and Sciences (Swietokrzyska Pedagogical
University) / Uniwersytet Humanistyczno Przyrodniczy Jana Kochanowskiego
w Kielcach</a></td>
I want to replace to be like that:
<tr class="even">
<td>Jan Kochanowski University of Humanities and Sciences (Swietokrzyska Pedagogical University) / Uniwersytet Humanistyczno Przyrodniczy Jana Kochanowskiegow Kielcach</td>
I tried that REGEX: (.*)
But didn't work.
Open the replace window with Ctrl + H
Then enter
Find what: ([^>])[\r\n]{1,2}
Replace with: \1
Check Regular Expression
[^>] matches a character that isn't a >
The {1,2} protects against a file that may only have a newline and not a carriage return.
\1 replaces just the character that was in the grouping ( ).
Open Notepad++
Click Search >> Replace..
Replace with: \n
At the bottom you will find "Search Mode", click "Extended"
Live example here: http://postimg.org/image/c66pw8kkr/
If you can't make jmstoker's solution work, try like this:
you need to check if the line breaks are just CRLF or just one of them, for that, click on the toolbar the icon "show all characters" or go to menu View -> Show Symbol -> Show all characters
in the replace dialog select the "Extended" search mode
in the "find what:" field, write this: \r\n (or just \r or just \n, basically match CR with \r and LF with \n)
leave the replace with field empty
once this is done, all the line breaks will have been replaced, but you want the <tr class="even"> to be on its own line, so just replace still using an extended search <tr class="even"><td> with <tr class="even">\r\n<td>
I'm guessing you also have rows with class "odd" or something like that so you might need to repeat that last step with the different class :)
In html I need to copy the text that is in the title tag, to a new line as a h1 tag in a certain place..
Example:
<TITLE>any text here, including special characters like .,:- or whataever</TITLE>
Output to leave that title as as, and then add a line under this:
under this line:
<font face="Arial"><span style="font-size: 14pt">
it adds
<h1 align="center">any text here, including special characters like .,:- or whataever</h1>
I use notepad++ to search and replace, but I don't think it would work in this case, so please suggest any other simple and effective Windows program to use, wish steps if any.. and I need to edit this in bulk for many files..
Thanks in advance,
As this question is still open, and you have a pretty bad accept rate, I'll try to offer you a solution:
Search for:
<TITLE>(.*)</TITLE>(.*?)<font face="Arial"><span style="font-size: 14pt">
And make sure to check the ". matches Newline" option in the search box. Then use the Following replace:
<TITLE>\1</TITLE>\2<font face="Arial"><span style="font-size: 14pt">\n<h1>\1</h2>
Worked in my notepad++.
The regex you need yo use should be like:
/^<TITLE>(.*)<\/TITLE>/
Now I'll give you a small Perl snippet that takes in a line, matches against the above regex and spits out the text in the title tags wrapped in <h1>...</h1>. Remember that in regexes, the parentheses are used to "group" matches - or in layman terms, to store them for future references. The script:
$line = <STDIN>;
chomp $line;
$line =~ /^<TITLE>(.*)<\/TITLE>/;
print "<h1>"."$1"."</h1>";
Here, all text between TITLE tags is grouped and hence stored in the variable $1.
When I do:
echo "<TITLE>lama</TITLE>" |script.pl
I get:
<h1>lama</h1>
Hope that helps.
I'm trying to replace tags in my code, but keeping the text inside "as is".
example string:
<p class="negrita">text1</p>
or
<p class="negrita">text2</p>
i need to get those replaced as so:
<h3>text1</h3>
and
<h3>text2</h3>
i'm searching (and matching fine) with this,
<p class="negrita">([^>]*)</p>
but I have no idea on how to keep the text inside, as
<h3>$1</h3>
is not working.
Instead of using regular expressions to do this, use Dreamweaver's Specific Tag search option. While regular expressions are possible in Dreamweaver, it's a bit crippled and sometimes a little buggy.
To do this with Specific Tag, invoke the search using Control-F
Change the search option to "Specific Tag".
Next to that, enter p to search for all <p> tags
Hit the + icon below the box to add an option and select "With Attribute" "Class" "=" from the first three pulldowns and type "negrita" in the fourth.
For action, select "Change Tag" and then select h3.
Run this and you will get <h3 class="negrita">text1</h3>
Then repeat the steps above, searching for all h3 tags with the class negrita and choose Remove Attribute "class" for the action. Two steps to one, I admit but it will work every time.