#2*\+ Wh#at# is\ Re#act*00:00 sdds#
#3 First React Code 01:15sdsdd
I am currently updating my chapters capturing function to behave like above. I am thinking about removing the regex below to remove the timestamps from the string containing a chapter:
/([^a-zA-Z0-9_](?:(\d{2}):)?(\d{2}):(\d{2}))/gm
(still a WIP)
Edit: I have come up with a way to extract the chapter title and its timestamp based on the experiences I made with YouTube chapters:
Qt C++ code:
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString str = "#2 (00:10:00) variables ✘";
str.prepend(' '); // force timestamp capture when they are at the beginning of the string
QRegularExpression re("(?:[^a-zA-Z0-9_=:])((?:(\\d{1,2}):)?(\\d{1,2}):(\\d{1,2}))(?:[^a-zA-Z0-9_=:])?");
QRegularExpression deletionRE("^[^a-zA-Z0-9!'\"_`\\[{(\\?]*|[^a-zA-Z0-9!)'\"_`}\\]\\.\\?]*$");
QRegularExpressionMatch match = re.match(str);
if(match.hasMatch())
{
qDebug() << "Match:" << match.captured(1);
qDebug() << "Hour:" << match.captured(2);
qDebug() << "Minute:" << match.captured(3);
qDebug() << "Second:" << match.captured(4);
qDebug() << "part1:" << str.mid(0, str.indexOf(match.captured(1)));
qDebug() << "part2:" << str.mid(str.lastIndexOf(match.captured(1)) + match.captured(1).size(), str.size() - 1);
QString part1 = str.mid(0, str.indexOf(match.captured(1)));
QString part2 = str.mid(str.lastIndexOf(match.captured(1)) + match.captured(1).size(), str.size() - 1);
str.remove(match.captured(1));
part1.remove(deletionRE);
part2.remove(deletionRE);
QString chapterTitle;
if(! part1.isEmpty() && ! part2.isEmpty())
{
chapterTitle = part1 + "." + part2;
}
else
{
chapterTitle = part1.isEmpty() ? part2 : part1;
}
chapterTitle.remove(deletionRE);
qDebug() << "Chapter Title" << chapterTitle;
}
}
Match: "00:10:00"
Hour: "00"
Minute: "10"
Second: "00"
part1: " #2 ("
part2: ") variables ✘"
Chapter Title "2.variables"