<?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: What is wrong with my regex? &amp;quot;Regex: missing terminating ] for character class&amp;quot; in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/What-is-wrong-with-my-regex-quot-Regex-missing-terminating-for/m-p/314053#M93983</link>
    <description>&lt;P&gt;Figured it out, splunk requires more escaping of slash characters&lt;/P&gt;</description>
    <pubDate>Tue, 28 Nov 2017 20:34:15 GMT</pubDate>
    <dc:creator>dbcase</dc:creator>
    <dc:date>2017-11-28T20:34:15Z</dc:date>
    <item>
      <title>What is wrong with my regex? "Regex: missing terminating ] for character class"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-is-wrong-with-my-regex-quot-Regex-missing-terminating-for/m-p/314051#M93981</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have this data&lt;BR /&gt;
    {"analyticType":"CustomAnalytic","buildTarget":"blah","clientSessionId":"DXFMLAF-CYTQQQK","Properties":{"index":1,"args":["{\"accountId\":\"exr244040\",\"customerId\":\"1001857\"}"],"category":"Event"}}&lt;/P&gt;

&lt;P&gt;And this regex (which works in regex101&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;accountId\\":\\"(?&amp;lt;extref&amp;gt;[^\\]+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but splunk barfs when I use it in this query&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=wholesale_app CustomAnalytic Properties.index=1|rex "accountId\\":\\"(?&amp;lt;extref&amp;gt;[^\\]+)"|stats count by extref
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;with this error message&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'rex' command: Encountered the following error while compiling the regex 'accountId\:\(?&amp;lt;extref&amp;gt;[^\]+)': Regex: missing terminating ] for character class
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(scratches head).....what am I doing wrong?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2017 19:41:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-is-wrong-with-my-regex-quot-Regex-missing-terminating-for/m-p/314051#M93981</guid>
      <dc:creator>dbcase</dc:creator>
      <dc:date>2017-11-28T19:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with my regex? "Regex: missing terminating ] for character class"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-is-wrong-with-my-regex-quot-Regex-missing-terminating-for/m-p/314052#M93982</link>
      <description>&lt;P&gt;Because the rex is in quotes, you need to escape the escape character(s) again, and then iterate testing it until it resolves.  &lt;/P&gt;

&lt;P&gt;Here's run-anywhere code...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval data = "{\"analyticType\":\"CustomAnalytic\",\"buildTarget\":\"blah\",\"clientSessionId\":\"DXFMLAF-CYTQQQK\",\"Properties\":{\"index\":1,\"args\":[\"{\\\"accountId\\\":\\\"exr244040\\\",\\\"customerId\\\":\\\"1001857\\\"}\"],\"category\":\"Event\"}}"
| rename COMMENT as "The above just enters your data as you posted it."

| rex field=data "accountId\\\\\":\\\\\"(?&amp;lt;accountId&amp;gt;[^\\\]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;updated from &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=data "accountId[\\\\][\\\"]:[\\\\][\\\"](?&amp;lt;accountId&amp;gt;[^\\\"\\\\]+)[\\\\][\\\"]"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In this case, I used this construct &lt;CODE&gt;[\\\\]&lt;/CODE&gt; to represent a single escape character \ , and the construct &lt;CODE&gt;[\\\"]&lt;/CODE&gt; to represent a single quote ".  &lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2017 20:34:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-is-wrong-with-my-regex-quot-Regex-missing-terminating-for/m-p/314052#M93982</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-11-28T20:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with my regex? "Regex: missing terminating ] for character class"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-is-wrong-with-my-regex-quot-Regex-missing-terminating-for/m-p/314053#M93983</link>
      <description>&lt;P&gt;Figured it out, splunk requires more escaping of slash characters&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2017 20:34:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-is-wrong-with-my-regex-quot-Regex-missing-terminating-for/m-p/314053#M93983</guid>
      <dc:creator>dbcase</dc:creator>
      <dc:date>2017-11-28T20:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with my regex? "Regex: missing terminating ] for character class"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-is-wrong-with-my-regex-quot-Regex-missing-terminating-for/m-p/314054#M93984</link>
      <description>&lt;P&gt;thanks DalJeanis!&lt;/P&gt;

&lt;P&gt;I ended up with&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex "accountId.....(?&amp;lt;extref&amp;gt;[^\\\]+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Nov 2017 20:35:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-is-wrong-with-my-regex-quot-Regex-missing-terminating-for/m-p/314054#M93984</guid>
      <dc:creator>dbcase</dc:creator>
      <dc:date>2017-11-28T20:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with my regex? "Regex: missing terminating ] for character class"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-is-wrong-with-my-regex-quot-Regex-missing-terminating-for/m-p/314055#M93985</link>
      <description>&lt;P&gt;Good job.  Updated to the simpler version. &lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2017 20:45:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-is-wrong-with-my-regex-quot-Regex-missing-terminating-for/m-p/314055#M93985</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-11-28T20:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with my regex? "Regex: missing terminating ] for character class"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-is-wrong-with-my-regex-quot-Regex-missing-terminating-for/m-p/624856#M217220</link>
      <description>&lt;P&gt;Thanks this worked for me&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2022 14:19:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-is-wrong-with-my-regex-quot-Regex-missing-terminating-for/m-p/624856#M217220</guid>
      <dc:creator>becksyboy</dc:creator>
      <dc:date>2022-12-20T14:19:09Z</dc:date>
    </item>
  </channel>
</rss>

