- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How do you extract a string within a longer string using regex?
I have an event that has a key-value output, and I need to extract the random string within the long string, for example, if my output string was "java.lang.RuntimeException: {Here is my random string} at com.quantum.myApp bla bla bla .....". How can I format the output to capture my random string. I've tried replace and rex unsuccessfully but it could be I did it wrong.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

The suggestion did not work, I initially needed to remove the first pipe before 'makeresults' because Splunk was complaining, but afterwards nothing showed up in the results.
No. that first pipe is needed for makeresults command.
The makeresults command is a generating command and should be the first command in the search. Generating commands use a leading pipe character.
https://docs.splunk.com/Documentation/Splunk/7.2.3/SearchReference/Makeresults
@whrg command works fine.. please check the screenshot:
| makeresults count=1
| eval _raw="java.lang.RuntimeException: {Here is my random string} at com.quantum.myApp bla bla bla"
| rex field=_raw "java\.lang\.RuntimeException:\s+\{(?[^\}]+)"
(PS - please accept @whrg 's answer as the accepted answer.. you can upvote this answer 😉 )
Sekar
PS - If this or any post helped you in any way, pls consider upvoting, thanks for reading !
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

hi @BenzionYunger,
Did you have a chance to check out whrg's answer? If it worked, please resolve this post by approving it! If your problem is still not solved, keep us updated so that someone else can help ya.
Thanks for posting!
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Check out this regex:
java\.lang\.RuntimeException:\s+\{(?<Exception>[^\}]+)
Here you can see it in action:
| makeresults count=1
| eval _raw="java.lang.RuntimeException: {Here is my random string} at com.quantum.myApp bla bla bla"
| rex field=_raw "java\.lang\.RuntimeException:\s+\{(?<Exception>[^\}]+)"
Now there is a new field named "Exception" with the value "Here is my random string".
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The suggestion did not work, I initially needed to remove the first pipe before 'makeresults' because Splunk was complaining, but afterwards nothing showed up in the results. My only guess is the raw expression is a randomly long string and I'm cutting if off after the first 12 words, I tried adding a wildcard at the end, but it didn't help. Maybe something needs to be refined. Here is the code I tried:
index="myIndex" makeresults count=1
| eval _raw="java.lang.RuntimeException: Sign in error message at com.quantum"
| rex field=_raw "java\.lang\.RuntimeException:\s+\{(?[^\}]+)"
