SPLK-1004 · Question #45
Which is a regex best practice?
The correct answer is B. Avoid backtracking. In regex (regular expressions), one of the best practices is to avoid backtracking when possible. Backtracking occurs when the regex engine revisits previous parts of the input string to attempt different permutations of the pattern, which can significantly degrade performance…
Question
Which is a regex best practice?
Options
- AUse complex expressions rather than simple ones.
- BAvoid backtracking.
- CUse greedy operators (. *) instead of non-greedy operators (. *? ).
- DUse * rather than +.
How the community answered
(39 responses)- A3% (1)
- B87% (34)
- C8% (3)
- D3% (1)
Explanation
In regex (regular expressions), one of the best practices is to avoid backtracking when possible. Backtracking occurs when the regex engine revisits previous parts of the input string to attempt different permutations of the pattern, which can significantly degrade performance, especially with complex patterns on large inputs. Designing regex patterns to minimize or avoid backtracking can lead to more efficient and faster evaluations.
Topics
Community Discussion
No community discussion yet for this question.