Atomic groups in regular expressions 0 ▲ Siderite's Blog 1 hour ago · Tech · hide · 0 comments Intro Rarely, but consistently, people using regular expressions meet a scenario where a regular expression becomes incredibly slow. This is called "catastrophic backtracking". There are multiple solutions for this, but the one I am going to be talking today is atomic groups. Definition An atomic group has the syntax: (?>subexpression) . It instructs the regular expression engine that it should greedily match the subexpression and never backtrack. In other words, once it has matched, the engine discards the group's backtracking positions. This leads to a huge performance improvement, but also that if the pattern fails, the engine cannot re-enter the group to try an alternative match. This is also called "non-backtracking subexpression" or "possessive". (possessive quantifiers like a++ are the same idea). How backtracking works Greedy quantifiers take as much as possible, then give characters back on failure. Alternation tries branch 1, then branch 2, and so on. Each choice point is… No comments yet. Log in to reply on the Fediverse. Comments will appear here.