I have a lot of html files with text without <p>. tags in the code.
I try find and replace with Adobe Brackets or Sublime Text 2:
Find <br><br>\n
Replace </p>\n</p>
But they do not find the \n in the code
Simplified, now I have:
Some sentence, some sentence<br><br>
(I have one space here in the code)
Some sentence, some sentence<br><br>
I would like to convert:
Some sentence, some sentence</p>
<p>Some sentence, some sentence</p>
(I know I will have to add manually just one <p> at the beginning, this is not important and it is not the point of this question)
Match a br with followed spaces (regex spaces includes \n\r\t ...):
<br\s*\/?>\s*
You can then replace with your string with global search.
Edit: I saw that your replacement is not just a carriage return, which will be messy with my example.
I would go for a two steps, replace any br by \n then apply your p elements by replacing multiple \n\s*.
Find:(.*)<br><br>\n?
Replace:<p>\1</p>\n
InPut:
Some sentence, some sentence<br><br>
Some sentence, some sentence<br><br>
OutPut:
<p>Some sentence, some sentence</p>
<p>Some sentence, some sentence</p>
Related
In my html page I have a lot of strings inside tags.
like
<p>Some string 1</p>
<p>Some string 2</p>
<p>Any string 3</p>
I need to put all of them to attribute TRANSLATE, lowercase them and replace all spaces to underscores inside strings.
So I multiselect all of them with holded CTRL, then ctrl+K, ctrl+L make them lowercase, CTRL+x - erase, two left arrows for going inside tags, write translate="PASTE HERE"
Now I have
<p translate="some string 1"></p>
<p translate="some string 2"></p>
<p translate="any string 3"></p>
Next step - I need to make underscores instead of spaces.
To find all translate strings I use regex (?s)translate=".+?"
But how to replace? Help.
Type ctrl + H and then
Use negative-lookbehind to search spaces which are not preceded by p.
(?<!p)\h+
\h matches only horizontal spaces.
Now replace-all it with _.
This is simple but will work and faster than looking for a smarter answer.
Find this: translate="(.*) (.*)"
Replace with this: translate="\1_\2"
Keep using Replace All until all your unwanted spaces are underscores (in the example you gave, twice).
I need to match text between two tags, but starting at a specific occurrence of the tag.
Imagine this text:
Some long <br> text goes <br> here. And some <br> more can <br> go here.<br>
In my example, I would like to match here. And some.
I successfully matched the text between the first occurrence (between the first and second br tags) with:
<br>(.*?)<br>
But I am looking for the text in the next match (which would be between the second and third br tags). This is probably more obvious than I realize, but Regex is not my strong suite.
Just extend your regex:
<br>(.*?)<br>(.*?)<br>
or, for an unlimited number of matches, and trimming the spaces:
<br>\s*(.*?)(?=\s*<br>)
EDIT: Now that I see that you are parsing an HTML document, be aware that regular expressions may not be the best tool for that job, especially if your parsing requirements are complex.
i have this string
<p> this is some text</p>
can be any number of times
to match i am using regex (?<=<p.*?>* )(.*)(?=</p>)
but i am getting this is some text as output
How to get this is some text
EDIT
i am sorry my string is <p class='randomstring'>a) this is some text</p>
in place of a) there is digit some times.
You can use this regex:
(?<=<p[^>]*>)(?: )+(.*)(?=</p>)
And grab the captured group #1 for you match, that will be:
this is some text
EDIT: Based on your edited question try this regex:
(?<=<p[^>]*>)[^)]*\) *(?: )+(.*)(?=</p>)
You could use the below regex which uses variable length positive lookbehind.
(?<=<p[^>]*>(?: )+)\b.*?(?=</p>)
This should match only the string this is some text
Update:
(?<=<p[^>]*>\w*\)(?: )+)\b.*?(?=</p>)
I am using Sublime Text 2's regex search and replace tool and would like to search text that includes the \r and \n special characters but cannot see how just at the moment.
For example, I have the text:
<div class="head">\r\n
\r\n Keep this text\r\n</div>
Which I would like to transform into:
<h1>Keep this text</h1>
I would also like to factor in the eventuality that these \r\n characters may not be present.
How might I search accounting for \r\n being present and absent, and then remove them as per above? If two regex are required that's fine too.
So far I have <div class="head">(\w)+</div>, however this is stalled by the aforementioned \r\n.
I think you're looking for \s, which matches white space.
So your regex should be something like the following:
<div class="head">\s*(.+?)\s*</div>
If you can do this in ST2, then I think it would fit your need:
Find:
<div class="head">[\s\r\n]*([\w ]+)[\s\r\n]*<\/div>
Replace by:
<h1>$1</h1>
Demo
Assuming i got really really large list of random numbers in a text file each entry separated by newline how do i construct a xml structure.
Source
6253266057
3970002069
6837266077
...
Result wanted
<Random value="6253266057" />
..
I did string replace on Source but then it complained of unclosed string since last quote would have to be in last line making other entries look abandoned.
In some programming languages or even text editors you can replace:
^(\d+)$
with
<Random value="\1" />
Where \1 is matching number