SPLK-1002 Macros, Saved Searches and CIM Practice Question
A Splunk admin wants to create a macro that extracts the username from a log line that always starts with 'User: <username>'. The macro should be reusable across searches. Which definition is correct?
⚠ Common exam trap
Splunk often tests the distinction between `rex` (a transforming command) and `eval` (a non-transforming command), and candidates mistakenly try to use `eval` with regex functions that do not exist in Splunk.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
`rex field=_raw "User: (?<username>\S+)"`
The `rex` command with `field=_raw` and a named capturing group `(?<username>\S+)` extracts the username into a field called `username`. This is the standard Splunk way to perform regex extraction in a search, and wrapping it in a macro makes it reusable across searches without additional syntax.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
`rex field=_raw "User: (?<username>\S+)"`
Why this is correct
This is a valid macro definition for extraction.
- ✗
`eval username=extract("User: (?<username>\S+)")`
Why it's wrong here
eval cannot use extract with regex; rex is needed.
- ✗
`rex field=_raw "User: (?<username>\S+)" | eval username=$result$`
Why it's wrong here
$result$ is not a valid macro token for this purpose.
- ✗
`username = rex field=_raw "User: (?<username>\S+)"`
Why it's wrong here
In a macro definition, you cannot assign to a variable outside of eval.
Go deeper
Related to this question
About these practice questions
This SPLK-1002 question is part of Courseiva's 475-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This SPLK-1002 practice question is part of Courseiva's free Splunk certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the SPLK-1002 exam.