code should be something like this:
const mdtext = `some blabla text
Here is a table:
| a | b |
|---|---|
| 1 | 2 |
| ^ | 3 |
more text outside
Here goes another table
| apples | oranges | bananas |
|--------|---------|---------|
| 11 | 24 | 22 |
| 84 | 32 | 23 |
- some bullets
- more bullets
`;
const count = countTables(mdtext)
console.log(count); // it should output 2
This regex https://stackoverflow.com/a/29616512/865220 matches single header only, I need with multiple.
2
Answers
I have found a non-regex way to do it, It uses
remark
andrehype
libraries.For your sample data, I would suggest the following regex:
^(?:[ t]*|(?:.+?|)+[ t]*(?:[rn]|$))+
.Check it on regex101.
An explanation using artificial intelligence can be found here.