<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Splunk regex bug/issue in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Splunk-regex-bug-issue/m-p/690814#M235282</link>
    <description>&lt;P&gt;Thank you, the solution worked&lt;BR /&gt;I tried 4 &lt;SPAN&gt;backslashes&amp;nbsp;&lt;/SPAN&gt;and I noticed that you used 3, is there any important difference?&lt;/P&gt;</description>
    <pubDate>Sat, 15 Jun 2024 18:32:57 GMT</pubDate>
    <dc:creator>Josh1890</dc:creator>
    <dc:date>2024-06-15T18:32:57Z</dc:date>
    <item>
      <title>Splunk regex bug/issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-regex-bug-issue/m-p/690762#M235258</link>
      <description>&lt;P&gt;Hello, I have a case where I need to do regex&amp;nbsp; and I built my regex using regex101, everything works great and catchs everything there&lt;/P&gt;&lt;P&gt;But I encountred an issue where splunk won't accept optional groups "(\\\")?", it'll give the error of unmatched closing parenthesis until you add another closing bracket like so: "(\\\"))?"&lt;/P&gt;&lt;P&gt;And another issue I encountred is after I add this closing bracket, the regex will work, but not consistently&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Here's what I mean:&lt;/P&gt;&lt;P&gt;That's a part of my regex:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;\[\{(\\)?\"PhoneNumber(\\)?\":(\\)?\"(?&amp;lt;my_PhoneNumber&amp;gt;[^\\\"]+&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Won't work until I add more brackets to the optional groups like I mentioned before:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;\[\{(\\))?\"PhoneNumber(\\))?\":(\\))?\"(?&amp;lt;my_PhoneNumber&amp;gt;[^\\\"]+&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;second issue:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;adding another part will still work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;\[\{(\\))?\"PhoneNumber(\\))?\":(\\))?\"(?&amp;lt;my_PhoneNumber&amp;gt;[^\\\"]+)\S+OtherPhoneNumber(\\))?\":(\\))?(\"))?(?&amp;lt;myother_PhoneNumber&amp;gt;[^,\\\"]+|null)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Adding a third part with the exact same format as the second part won't, will give the error of unmatched closing parenthesis again:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;\[\{(\\))?\"PhoneNumber(\\))?\":(\\))?\"(?&amp;lt;my_PhoneNumber&amp;gt;[^\\\"]+)\S+OtherPhoneNumber(\\))?\":(\\))?(\"))?(?&amp;lt;myother_PhoneNumber&amp;gt;[^,\\\"]+|null)\S+Email(\\))?\":(\\))?(\"))?(?&amp;lt;email&amp;gt;[^,\\\"]+|null)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I missing something?&lt;BR /&gt;I know the regex itself works&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample data of the original log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[{"PhoneNumber":"+1 450555338","AlternativePhoneNumber":null,"Email":null,"VoiceOnlyPhoneNumber":null}]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[{\"PhoneNumber\":\"+20 425554005\",\"AlternativePhoneNumber\":\"+1 455255697\",\"Email\":\"Dam@test.com.us\",\"VoiceOnlyPhoneNumber\":null}]"}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[{\"PhoneNumber\":\"+1 459551561\",\"AlternativePhoneNumber\":\"+1 6155555533\",\"Email\":null,\"VoiceOnlyPhoneNumber\":\"+1 455556868\"}]&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 22:55:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-regex-bug-issue/m-p/690762#M235258</guid>
      <dc:creator>Josh1890</dc:creator>
      <dc:date>2024-06-14T22:55:41Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk regex bug/issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-regex-bug-issue/m-p/690766#M235261</link>
      <description>&lt;P&gt;Would it be possible to post some sample data. It's a bit too easy to get lost in what is supposed to be an escape character versus a character in your data. Please replace any real phone numbers with dummy values.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Escaping backslashes for regex expressions is always fun, but I suspect that's where your issues are coming from. Escaping a backslash in a regex from the search box requires four backslashes as there are two layers of escaping that are happening.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I try to construct regexs to avoid that:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults | eval phone_data="[{\"PhoneNumber\":\"123-456-7890\"}]"
| append [ | makeresults | eval phone_data="[{\\\"PhoneNumber\\\":\\\"111-111-1111\\\"}]" ]
| rex field=phone_data "PhoneNumber[^\d]+(?&amp;lt;my_PhoneNumber&amp;gt;[0-9-\(\)]+)"&lt;/LI-CODE&gt;&lt;P&gt;but if I'm making an incorrect assumption about the characters in aphone number, you can try&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=phone_data "PhoneNumber[^\d]+(?&amp;lt;my_PhoneNumber&amp;gt;[^\\\\\"]+)"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 22:31:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-regex-bug-issue/m-p/690766#M235261</guid>
      <dc:creator>P_vandereerden</dc:creator>
      <dc:date>2024-06-14T22:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk regex bug/issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-regex-bug-issue/m-p/690769#M235263</link>
      <description>&lt;P&gt;Thank you for your comment, I posted sample data in the original post and I will try your offer&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 22:56:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-regex-bug-issue/m-p/690769#M235263</guid>
      <dc:creator>Josh1890</dc:creator>
      <dc:date>2024-06-14T22:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk regex bug/issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-regex-bug-issue/m-p/690814#M235282</link>
      <description>&lt;P&gt;Thank you, the solution worked&lt;BR /&gt;I tried 4 &lt;SPAN&gt;backslashes&amp;nbsp;&lt;/SPAN&gt;and I noticed that you used 3, is there any important difference?&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jun 2024 18:32:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-regex-bug-issue/m-p/690814#M235282</guid>
      <dc:creator>Josh1890</dc:creator>
      <dc:date>2024-06-15T18:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk regex bug/issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-regex-bug-issue/m-p/690815#M235283</link>
      <description>&lt;P&gt;In my example, I use 3 backslashes when creating the sample data. To get&amp;nbsp;&lt;FONT face="arial black,avant garde" color="#339966"&gt;\"&lt;/FONT&gt; in a quoted string, you need escape the backslash&amp;nbsp;&lt;FONT face="arial black,avant garde" color="#339966"&gt;\\&lt;/FONT&gt;, and the quote&amp;nbsp;&lt;FONT face="arial black,avant garde" color="#339966"&gt;\"&lt;/FONT&gt;, resulting in&amp;nbsp;&lt;FONT face="arial black,avant garde" color="#339966"&gt;\\\"&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="arial, helvetica, sans-serif" color="#000000"&gt;In the regex, I avoided the need to match on backslashes, so any backslash is just the escape character. However, in my alternative method, you'll notice that there are 5 backslashes in a row. The processing of the escape characters happens once for the string itself, taking&amp;nbsp;&lt;FONT face="arial black,avant garde"&gt;&lt;FONT color="#339966"&gt;\\\\\"&lt;/FONT&gt;&amp;nbsp;&lt;/FONT&gt;down to&amp;nbsp;&lt;FONT face="arial black,avant garde" color="#339966"&gt;\\"&lt;/FONT&gt;, and then once for the regex, taking&amp;nbsp;&lt;FONT face="arial black,avant garde"&gt;&lt;FONT color="#339966"&gt;\\"&lt;/FONT&gt;&amp;nbsp;&lt;/FONT&gt;down to &lt;FONT face="arial black,avant garde" color="#339966"&gt;\"&lt;/FONT&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;.&lt;/FONT&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jun 2024 19:46:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-regex-bug-issue/m-p/690815#M235283</guid>
      <dc:creator>P_vandereerden</dc:creator>
      <dc:date>2024-06-15T19:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk regex bug/issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-regex-bug-issue/m-p/690820#M235284</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;P&gt;Sample data of the original log:&lt;/P&gt;&lt;P&gt;[{"PhoneNumber":"+1 450555338","AlternativePhoneNumber":null,"Email":null,"VoiceOnlyPhoneNumber":null}]&lt;/P&gt;&lt;P&gt;[{\"PhoneNumber\":\"+20 425554005\",\"AlternativePhoneNumber\":\"+1 455255697\",\"Email\":\"Dam@test.com.us\",\"VoiceOnlyPhoneNumber\":null}]"}&lt;/P&gt;&lt;P&gt;[{\"PhoneNumber\":\"+1 459551561\",\"AlternativePhoneNumber\":\"+1 6155555533\",\"Email\":null,\"VoiceOnlyPhoneNumber\":\"+1 455556868\"}]&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Do you mean to say that some log contains valid JSON, some contains quote-escaped JSON? &amp;nbsp;Or was the first entry a misprint; all logs are in fact quote-escaped JSON, like the following?&lt;/P&gt;&lt;TABLE width="785px"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;log&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="784px"&gt;[{\"PhoneNumber\":\"+1 450555338\",\"AlternativePhoneNumber\":null,\"Email\":null,\"VoiceOnlyPhoneNumber\":null}]&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="784px"&gt;[{\"PhoneNumber\":\"+20 425554005\",\"AlternativePhoneNumber\":\"+1 455255697\",\"Email\":\"Dam@test.com.us\",\"VoiceOnlyPhoneNumber\":null}]&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="784px"&gt;[{\"PhoneNumber\":\"+1 459551561\",\"AlternativePhoneNumber\":\"+1 6155555533\",\"Email\":null,\"VoiceOnlyPhoneNumber\":\"+1 455556868\"}]&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;In this illustration, I assume that the "original log" contains some additional elements; only one field (named &lt;U&gt;log&lt;/U&gt;) contains those escaped JSON because it is very unreasonable to escape quotation marks if it is the complete log.&lt;/P&gt;&lt;P&gt;If as I speculated, all log values are escaped, you should aim at reconstructing JSON, not use rex to treat them as text. &amp;nbsp;So, I recommend&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=log mode=sed "s/\\\\\"/\"/g"
| spath input=log path={}
| mvexpand {}
| spath input={}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using Splunk's built-in JSON handling is more robust than any regex you can craft. &amp;nbsp;From the mock data, the above will give you&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;AlternativePhoneNumber&lt;/TD&gt;&lt;TD&gt;Email&lt;/TD&gt;&lt;TD&gt;PhoneNumber&lt;/TD&gt;&lt;TD&gt;VoiceOnlyPhoneNumber&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;null&lt;/TD&gt;&lt;TD&gt;null&lt;/TD&gt;&lt;TD&gt;+1 450555338&lt;/TD&gt;&lt;TD&gt;null&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;+1 455255697&lt;/TD&gt;&lt;TD&gt;Dam@test.com.us&lt;/TD&gt;&lt;TD&gt;+20 425554005&lt;/TD&gt;&lt;TD&gt;null&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;+1 6155555533&lt;/TD&gt;&lt;TD&gt;null&lt;/TD&gt;&lt;TD&gt;+1 459551561&lt;/TD&gt;&lt;TD&gt;+1 455556868&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;This is the emulation for the data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval log = mvappend("[{\\\"PhoneNumber\\\":\\\"+1 450555338\\\",\\\"AlternativePhoneNumber\\\":null,\\\"Email\\\":null,\\\"VoiceOnlyPhoneNumber\\\":null}]",

"[{\\\"PhoneNumber\\\":\\\"+20 425554005\\\",\\\"AlternativePhoneNumber\\\":\\\"+1 455255697\\\",\\\"Email\\\":\\\"Dam@test.com.us\\\",\\\"VoiceOnlyPhoneNumber\\\":null}]",

"[{\\\"PhoneNumber\\\":\\\"+1 459551561\\\",\\\"AlternativePhoneNumber\\\":\\\"+1 6155555533\\\",\\\"Email\\\":null,\\\"VoiceOnlyPhoneNumber\\\":\\\"+1 455556868\\\"}]")
| mvexpand log
``` data emulation above ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Jun 2024 00:43:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-regex-bug-issue/m-p/690820#M235284</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-06-16T00:43:00Z</dc:date>
    </item>
  </channel>
</rss>

