Im trying to turn text into an HTML table and im stuck on the part to separate rows.
Lets say I started with text that was displayed like this:
1: a
2: w
3: p
Then with a little bit of REGEX I turned it into
<td>1</td>
<td>a</td>
<td>2</td>
<td>w</td>
<td>3</td>
<td>p</td>
Now how (with REGEX) would I turn that into this:
<tr>
<td>1</td>
<td>a</td>
</tr>
<tr>
<td>2</td>
<td>w</td>
</tr>
<tr>
<td>3</td>
<td>p</td>
</tr>
The indents are just there so you can see it better, I dont actually want it to add them.
So somehow I would make it look for
<td>[0-9]
Then select that and the next line then add the and to it by doing
<td>\1<\td>
But I dont know how to do that entirely, if anyone can understand that mess could you help me please? D:
Edit: Worked it out!
I started with
1: a
2: w
3: p
Then I did this:
Find: ": "
Replace: "\r\n"
Then
Find: "([0-9])"
Replace: "<td>\1<td>"
Then
Find: "^([^<]+)$"
Replace: ""
Then
Find: "(<td>[0-9]</td>)[\r][\n]"
Replace: "\1"
Huehuehue, then
Find: "^(.*<td>[0-9]*+)$"
Replace: "<tr>\1</tr>"
There was probably a MUCH easier way to do this, but I finally got it 😀
Your first regex should convert the initial text into 3 lines, not 6 as you show:
Then the problem becomes relatively simple.