I’m trying to get a set of strings from a paragraph that match the format of 4chan’s quotes: >>1111111
where it starts with >>
followed by 7 digits.
JavaScript
x
4
1
>>1111000
2
>>1111001
3
Yes, I agree with those sentiments.
4
Both >>1111000
and >>1111001
would be extracted from the text above which I would then split into the digits after.
Advertisement
Answer
You can use the following which will match lines starting with 2 >
characters followed by 7 digits:
JavaScript
1
9
1
const regex =/^[>]{2}[d]{7}$/gm;
2
3
const text = `>>1234567
4
>>6548789
5
foo barr`;
6
7
const matches = text.match(regex);
8
9
console.log(matches);