Splunk Search

Regex Error with Splunk SOAR/Phantom

luffy
Engager

I have a regex to extract filename from object field. This works completely fine in Search.
index="test" | rex field=object "(?P<fileName>[^\\\]+)$"

However, when I try to input the below custom code in Splunk SOAR, it always returns an error "HTTP 400 Bad Request -- Error in 'rex' command: Encountered the following error while compiling the regex '(?P<fileName>[^\\]+)$': Regex: missing terminating ] for character class."


sql_search_query=rf"""
index="test"
| rex field=object "(?P<fileName>[^\\\]+)$"
"""
parameters = []
parameters.append({
"command": "search",
"search_mode": "smart",
"add_raw_field": False,
"query": sql_search_query,
"parse_only": True,
"start_time": "-90d",
"end_time": 0,
})


Labels (4)
0 Karma
1 Solution

PrewinThomas
Motivator

@luffy 

Looks like escape character causing the issue. Can you try double escaping

sql_search_query = """
index="test"
| rex field=object "(?P<fileName>[^\\\\]+)$"
"""


Regards,
Prewin
If this answer helped you, please consider marking it as the solution or giving a Karma. Thanks!

View solution in original post

0 Karma

PrewinThomas
Motivator

@luffy 

Looks like escape character causing the issue. Can you try double escaping

sql_search_query = """
index="test"
| rex field=object "(?P<fileName>[^\\\\]+)$"
"""


Regards,
Prewin
If this answer helped you, please consider marking it as the solution or giving a Karma. Thanks!

0 Karma
Get Updates on the Splunk Community!

.conf25 Community Recap

Hello Splunkers, And just like that, .conf25 is in the books! What an incredible few days — full of learning, ...

Splunk App Developers | .conf25 Recap & What’s Next

If you stopped by the Builder Bar at .conf25 this year, thank you! The retro tech beer garden vibes were ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...