<?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 How to end a Rex search with mutiple characters or a string sub as } }? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-end-a-Rex-search-with-mutiple-characters-or-a-string-sub/m-p/483179#M193290</link>
    <description>&lt;P&gt;Sample data:
&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
&lt;CODE&gt;{ "active" : "Y“, “locationID" : 75942068, "existsFlag" : true, "manuallyUnarchived" : false, "pendingReminder" : false, "headerOperationType" : "TRN“, “headerCreationDateString" : "2019111307255700“, “headerCreationDateEpoch" : "1573651557“, “jobs" : [ { "jobNumber" : "RWERQ70“, “jobVendorNum" : "ACME“, “jobAcknowledgementDateString" : "2019-11-08:10:42“, “jobAcknowledgementDateEpoch" : "1573231320“, “jobPodDateString" : "2019-11-13:05:44“, “jobPodDateEpoch" : "1573645440“, “jobShipDateString" : "2019-11-08:11:20“, “jobShipDateEpoch" : "1573233600“, “jobStatusCode" : "DELIVERED“, “jobPartNumbers" : [ { "skuMfgNbr" : "AS3452“, “quantity" : 1 } ], "partShippedDescription" : "SHP142SVC" } ], "comments" : [ { "commentType" : "PRB“, “commentDateEpoch" : "1573192800000“, “arrivalWindowStart" : 1573477200000, "arrivalWindowEnd" : 1573858740000, "avsUsed" : "N“, “laborStatusCode" : "ETA Provided“, “partStatusCode" : "Delivered“, “owner" : { "businessUnit" : 0, "certifiedFlag" : false, "techId" : 0 }, "environment" : "None“, “subEnvironment" : "Other“, “shortComment" : "TechDirection : Other“, “dispatchCreationDateEpoch" : "1573230503“, “serviceAttributes" : { "ServiceType" : "FixerUpper“, “OutofHours" : "N“, “OutofWarranty" : "N“, “ServiceHours" : "10x1“, “ADOverrideRequest" : "N" } }, "address" : { "address" : "1 Main St“, “address1" : "1 Main St“, “city" : "Nowhere“, “country" : "US“, “postalCode" : "12345" }&lt;/CODE&gt;
&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;I need a field containing all the text from "activity" all the way to } }, (the double curly brackets separated by a space and followed by a comma, located right before "address" field. I could do this with if a single terminator character ( } ), as in the example below, but that would only give me half of the data needed. I need a Rex that gives me all the data betwen "activity" and the } } (the two curly brackets). The two curly brackets indicate the end of the main field).
&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;This works: &lt;CODE&gt;| rex field=_raw "\"activity\"(?&amp;amp;ltACTIVITY_FIELDS&amp;gt;[^\}]+)"&lt;/CODE&gt;
&lt;/P&gt;&lt;P&gt;This is what I need, but it does not work: &lt;CODE&gt;| rex field=_raw "\"activity\"(?&amp;amp;ltACTIVITY_FIELDS&amp;gt;[^\}\s\}]+)"&lt;/CODE&gt;
&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;Thanks for any assistance provided. &lt;/P&gt;</description>
    <pubDate>Thu, 14 Nov 2019 00:31:54 GMT</pubDate>
    <dc:creator>ryanksplunkster</dc:creator>
    <dc:date>2019-11-14T00:31:54Z</dc:date>
    <item>
      <title>How to end a Rex search with mutiple characters or a string sub as } }?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-end-a-Rex-search-with-mutiple-characters-or-a-string-sub/m-p/483179#M193290</link>
      <description>&lt;P&gt;Sample data:
&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
&lt;CODE&gt;{ "active" : "Y“, “locationID" : 75942068, "existsFlag" : true, "manuallyUnarchived" : false, "pendingReminder" : false, "headerOperationType" : "TRN“, “headerCreationDateString" : "2019111307255700“, “headerCreationDateEpoch" : "1573651557“, “jobs" : [ { "jobNumber" : "RWERQ70“, “jobVendorNum" : "ACME“, “jobAcknowledgementDateString" : "2019-11-08:10:42“, “jobAcknowledgementDateEpoch" : "1573231320“, “jobPodDateString" : "2019-11-13:05:44“, “jobPodDateEpoch" : "1573645440“, “jobShipDateString" : "2019-11-08:11:20“, “jobShipDateEpoch" : "1573233600“, “jobStatusCode" : "DELIVERED“, “jobPartNumbers" : [ { "skuMfgNbr" : "AS3452“, “quantity" : 1 } ], "partShippedDescription" : "SHP142SVC" } ], "comments" : [ { "commentType" : "PRB“, “commentDateEpoch" : "1573192800000“, “arrivalWindowStart" : 1573477200000, "arrivalWindowEnd" : 1573858740000, "avsUsed" : "N“, “laborStatusCode" : "ETA Provided“, “partStatusCode" : "Delivered“, “owner" : { "businessUnit" : 0, "certifiedFlag" : false, "techId" : 0 }, "environment" : "None“, “subEnvironment" : "Other“, “shortComment" : "TechDirection : Other“, “dispatchCreationDateEpoch" : "1573230503“, “serviceAttributes" : { "ServiceType" : "FixerUpper“, “OutofHours" : "N“, “OutofWarranty" : "N“, “ServiceHours" : "10x1“, “ADOverrideRequest" : "N" } }, "address" : { "address" : "1 Main St“, “address1" : "1 Main St“, “city" : "Nowhere“, “country" : "US“, “postalCode" : "12345" }&lt;/CODE&gt;
&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;I need a field containing all the text from "activity" all the way to } }, (the double curly brackets separated by a space and followed by a comma, located right before "address" field. I could do this with if a single terminator character ( } ), as in the example below, but that would only give me half of the data needed. I need a Rex that gives me all the data betwen "activity" and the } } (the two curly brackets). The two curly brackets indicate the end of the main field).
&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;This works: &lt;CODE&gt;| rex field=_raw "\"activity\"(?&amp;amp;ltACTIVITY_FIELDS&amp;gt;[^\}]+)"&lt;/CODE&gt;
&lt;/P&gt;&lt;P&gt;This is what I need, but it does not work: &lt;CODE&gt;| rex field=_raw "\"activity\"(?&amp;amp;ltACTIVITY_FIELDS&amp;gt;[^\}\s\}]+)"&lt;/CODE&gt;
&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;Thanks for any assistance provided. &lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 00:31:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-end-a-Rex-search-with-mutiple-characters-or-a-string-sub/m-p/483179#M193290</guid>
      <dc:creator>ryanksplunkster</dc:creator>
      <dc:date>2019-11-14T00:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to end a Rex search with mutiple characters or a string sub as } }?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-end-a-Rex-search-with-mutiple-characters-or-a-string-sub/m-p/483180#M193291</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;can you please check the given sample data, "activity" keyword is not there.&lt;BR /&gt;
One more thing, your json data format is not correct, its having tow types of double quotes,&lt;BR /&gt;
&lt;CODE&gt;"   U+0022 QUOTATION MARK&lt;BR /&gt;
“   U+201C LEFT DOUBLE QUOTATION MARK&lt;/CODE&gt;&lt;BR /&gt;
check the difference at first key value pair &lt;CODE&gt;"Y“&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Once your data is in correct format, you can ingest it as json format and use &lt;CODE&gt;spath&lt;/CODE&gt; command to get values of keys.&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 07:55:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-end-a-Rex-search-with-mutiple-characters-or-a-string-sub/m-p/483180#M193291</guid>
      <dc:creator>gaurav_maniar</dc:creator>
      <dc:date>2019-11-14T07:55:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to end a Rex search with mutiple characters or a string sub as } }?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-end-a-Rex-search-with-mutiple-characters-or-a-string-sub/m-p/483181#M193292</link>
      <description>&lt;P&gt;Hi @ryanksplunkster,&lt;BR /&gt;
I tried to analyze your sample but the word &lt;CODE&gt;activity&lt;/CODE&gt; isn't in it, so I cannot test it.&lt;/P&gt;

&lt;P&gt;Anyway I see two problems in your regex:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;&lt;CODE&gt;}&lt;/CODE&gt; is a special char and must be escaped.&lt;/LI&gt;
&lt;LI&gt;the group &lt;CODE&gt;[^\}]*&lt;/CODE&gt; means all the chars until &lt;CODE&gt;}&lt;/CODE&gt;, so you cannot insert a group &lt;CODE&gt;\}\s\}&lt;/CODE&gt; in square brackets.&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;So, if you want to take text between &lt;CODE&gt;serviceAttributes&lt;/CODE&gt; and &lt;CODE&gt;}}&lt;/CODE&gt; you should try something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;serviceAttributes\"\s+:\s+\{\s+(?&amp;lt;my_field&amp;gt;[^\}]*)\}\s\}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can test it at &lt;A href="https://regex101.com/r/gDamxB/1"&gt;https://regex101.com/r/gDamxB/1&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Ciao.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 08:15:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-end-a-Rex-search-with-mutiple-characters-or-a-string-sub/m-p/483181#M193292</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2019-11-14T08:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to end a Rex search with mutiple characters or a string sub as } }?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-end-a-Rex-search-with-mutiple-characters-or-a-string-sub/m-p/483182#M193293</link>
      <description>&lt;P&gt;Gaurav, thank you for your response.  Here's a better data sample (now complete and properly formatted):&lt;/P&gt;

&lt;P&gt;"parts" : [ { "Mfg" : "SLF347", "Description" : "OP SYS", "quantity" : 1, "target" : 0, "Name" : "ACME", "quantityAT" : 0, "Mode" : "Manual" }, { "sku" : "8-45612-65423-0", "pDesc" : "INFOSERV", "quantity" : 1, "Name" : "ACME", "Mode" : "Manual" } ], "region" : "US", "scheduled" : false, "LevelEpoch" : "1570750199", "account" : { "channel" : "USPA" }, "activity" : { "dNumber" : 718526123, "build" : 12, "TimeZone" : "GMT-08:00", "description" : "Windows 10", "groupName" : "WestGroup", "id" : "A-2KJLSJRHE", "priority" : "Low", "reasonCode" : "GH5HTH", "recordType" : "Fix", "status" : "DCNR", "statusDescription" : "Def Request", "solution" : "Re-install", "AgencyRev" : false, "statusDateEpoch" : "1573715886", "rCount" : 1, "arrivalTimezone" : "GMT-06:00", "Start" : 1569938400000, "End" : 1571097540000, "Used" : "Y", "laborCode" : "Ackgd", "partCode" : "Ced", "note" : "Issue Description : Re-Install", "owner" : { "BU" : 0, "certFlag" : false, "name" : "John Doe", "Id" : 0 }, "environment" : "None", "subEnvironment" : "Other", "serialNumber" : "ADN0970234529387509237", "UID" : "B-4FJFLL", "DateEpoch" : "1569701589", "repeat" : "N", "servAtt" : { "ServiceType" : "Fix", "ServiceSubType" : "WH", "Billable" : "N", "CompleteUnit" : "N", "OutHour" : "N", "OutWarranty" : "N", "ServHour" : "365x24x7", "Level" : "10", "ProviderId" : "LEK", "ServpProvider" : "LEK", "System" : "Notebook", "Deferred" : "No", "Cover" : "5-10x5", "ScheduleFlag" : "N", "Component" : "N" } }, "address" : { "address" : "1 Main St", "address1" : "1 Main St", "city" : "Nowhere", "country" : "US", "postalCode" : "12345", "region" : "US", "state" : "ZZ", "timeZone" : "GMT-08:00" }&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 13:48:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-end-a-Rex-search-with-mutiple-characters-or-a-string-sub/m-p/483182#M193293</guid>
      <dc:creator>ryanksplunkster</dc:creator>
      <dc:date>2019-11-14T13:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to end a Rex search with mutiple characters or a string sub as } }?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-end-a-Rex-search-with-mutiple-characters-or-a-string-sub/m-p/483183#M193294</link>
      <description>&lt;P&gt;Hi @ryanksplunkster,&lt;BR /&gt;
try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;activity\"\s+:\s+\{\s+(?&amp;lt;ACTIVITY_FIELDS&amp;gt;.*)\}\s+\}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;that you can test at &lt;A href="https://regex101.com/r/kfQ1wR/1"&gt;https://regex101.com/r/kfQ1wR/1&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Ciao.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 13:58:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-end-a-Rex-search-with-mutiple-characters-or-a-string-sub/m-p/483183#M193294</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2019-11-14T13:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to end a Rex search with mutiple characters or a string sub as } }?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-end-a-Rex-search-with-mutiple-characters-or-a-string-sub/m-p/483184#M193295</link>
      <description>&lt;P&gt;Thanks, everybody, for your support.&lt;/P&gt;

&lt;P&gt;It turns out my data had line breaks in it, so the solution provided by gcusello worked perfectly on rex101, but failed on my actual search. Nevertheless, I got a hint to add "(?s)" to the beginning of the search. That returned results, but did not terminate at the two }} (I still don't understand why). So I extended the search to the next field name and that worked well. The final solution was:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| rex field=_raw  "(?s)"\"activity\"\s+:\s+{\s+(?&amp;lt;ACTIVITY_FIELDS&amp;gt;.*)\"address\"&lt;CODE&gt;&lt;BR /&gt;
&lt;/CODE&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:57:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-end-a-Rex-search-with-mutiple-characters-or-a-string-sub/m-p/483184#M193295</guid>
      <dc:creator>ryanksplunkster</dc:creator>
      <dc:date>2020-09-30T02:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to end a Rex search with mutiple characters or a string sub as } }?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-end-a-Rex-search-with-mutiple-characters-or-a-string-sub/m-p/483185#M193296</link>
      <description>&lt;P&gt;Hi @ryanksplunkster ,&lt;/P&gt;

&lt;P&gt;Your problem will be solved by using regex provided by @gcusello .&lt;/P&gt;

&lt;P&gt;This is just for better practice and suggestions.&lt;/P&gt;

&lt;P&gt;If you can properly format your JSON and ingest the data, Splunk will automatically extract all the fields.&lt;BR /&gt;
And by using &lt;CODE&gt;spath&lt;/CODE&gt; command you can group json elements and extract the required values without writing regex.&lt;/P&gt;

&lt;P&gt;I have formatted your json sample data - &lt;A href="https://jsonblob.com/d8185020-06e9-11ea-b8b2-d99444fde766"&gt;https://jsonblob.com/d8185020-06e9-11ea-b8b2-d99444fde766&lt;/A&gt;&lt;BR /&gt;
In this case, the &lt;CODE&gt;activity&lt;/CODE&gt; can be easily extracted by appending &lt;CODE&gt;| spath output=ACTIVITY_FIELDS path=activity&lt;/CODE&gt; to your query.&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 14:39:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-end-a-Rex-search-with-mutiple-characters-or-a-string-sub/m-p/483185#M193296</guid>
      <dc:creator>gaurav_maniar</dc:creator>
      <dc:date>2019-11-14T14:39:30Z</dc:date>
    </item>
  </channel>
</rss>

