Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
You won't be able to do it for arbitrary length tables in a single regex matching the whole row. Capture groups are replaced when repeated. So any \| (?:(cell_text) \|)+ expression[1] will wind up ...
#2: Post edited
You won't be able to do it for arbitrary length tables in a single regex alone. Capture groups are replaced when repeated. So any `\| (?:(cell_text) \|)+` expression[^ws] will wind up with the capture group `\g<1>` as the last cell's text.- Instead, you'd have to send, say `\|?[ \t]*(.*?)[ \t]s*\|` to `re.sub` to replace each cell in a row with `<td>\1</td>` and wrap _that_ in `<tr></tr>`.
- [^ws]: Irrespective of whitespace
- You won't be able to do it for arbitrary length tables in a single regex matching the whole row. Capture groups are replaced when repeated. So any `\| (?:(cell_text) \|)+` expression[^ws] will wind up with the capture group `\g<1>` as the last cell's text.
- Instead, you'd have to send, say `\|?[ \t]*(.*?)[ \t]s*\|` to `re.sub` to replace each cell in a row with `<td>\1</td>` and wrap _that_ in `<tr></tr>`.
- [^ws]: Irrespective of whitespace
#1: Initial revision
You won't be able to do it for arbitrary length tables in a single regex alone. Capture groups are replaced when repeated. So any `\| (?:(cell_text) \|)+` expression[^ws] will wind up with the capture group `\g<1>` as the last cell's text. Instead, you'd have to send, say `\|?[ \t]*(.*?)[ \t]s*\|` to `re.sub` to replace each cell in a row with `<td>\1</td>` and wrap _that_ in `<tr></tr>`. [^ws]: Irrespective of whitespace
