nerdexam
Splunk

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…

Advanced Search Commands and Techniques

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)
  • A
    3% (1)
  • B
    87% (34)
  • C
    8% (3)
  • D
    3% (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

#regex best practices#backtracking#greedy operators#search performance

Community Discussion

No community discussion yet for this question.

Full SPLK-1004 Practice