<?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 Rex command help in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Rex-command-help/m-p/685596#M233932</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I need your help with a field extraction.&lt;BR /&gt;I have this type of data, and I'd like to extract the following fields with a rex command:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="anissabnk_0-1714121324502.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/30577i1E19D4A119F2DCBC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="anissabnk_0-1714121324502.png" alt="anissabnk_0-1714121324502.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The syntax is as follows :&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;("data": ["from" :
"2024-04-25T11: 30Z",
"to": "2024-04-2512:00Z",
"intensity": ("forecast": 152,
"actual": null, "index": "moderate"}), ("from": "2024-04-25T12:002",
"intensity": {"forecast": 152, "actual": null, "index": "moderate"}), ("from": "2024-04-25T12:30Z",
"to":
{"from": "2024-04-25T13:00Z", "to":
"2024-04-25T12: 30Z",
("forecast": 164,
"actual": null,
"2024-04-2513: 30Z", "intensity": ("forecast": 154,
"to": "2024-04-25T13: 002",
"intensity": ("forecast": 154,
"actual": null,
"index":
"actual": null, "index": "moderate"}), ("from": "2024-04-25T13:30Z*, "to": "2024-04-25T14:002",
"moderate"}},
"intensity"：
04-25T14: 30Z",
"to" :
"index": "moderate"3}, ("from": "2024-04-25T14:002*, "to": "2024-04-25T14:30Z", "intensity": ("forecast": 166, "actual": null, "index": "moderate"}), ("from":
" 2024-04-25T15:00Z"
"actual": nu11,
"index"
"intensity": {"forecast": 170, "actual": null, "index": "moderate"}), {"from": "2024-04-2515: 00Z",
2024-
"to" :
"moderate"}), {"from": "2024-04-25T15:30Z", "to": "2024-04-25T16:00Z", "intensity": ("forecast": 175,
"to": "2024-04-25T15: 30Z",
"intensity": {"forecast": 172,
"2024-04-25T16: 30Z",
"index": "moderate"}}, ("from": "2024-04-25T17:00Z", "to":
"intensity": ("forecast": 177, "actual": null, "index": "moderate"?), ("from": "2024-04-2516: 302",
"actual" : nu11,
"index"
"moderate"}}, ("from": "2024-04-2516: 00Z",
"to": "2024-04-25T17:002",
"intensity": ("forecast": 179,
"actual": null,
2024-04-2517: 30Z", "intensity": ("forecast": 181, "actual": null,
25T18:00Z", "intensity": ("forecast": 184,
"index": "moderate"}}, {"from": "2024-04-25T17: 30Z",
"actual": null, "index": "moderate"}), ("from": "2024-04-25T18:002", "to": "2024-04-25T18: 30Z",
"to": "2024-04-
"moderate"}}, ("from": "2024-04-2518: 30Z", "to": "2024-04-25T19:002",
"intensity": ("forecast": 187, "actual": null,
"intensity": ("forecast": 190,
"actua1": nul1,
"index":
"index":
"high"}}, ("from":
"intensity": {"forecast": 193,
"actual": null, "index":
"2024-04-25T19: 00Z", "to":
"2024-04-25T19: 30Z"
"high"}}, ("from": "2024-04-25T19:30Z", "to": "2024-04-25T20:00Z", "intensity":
{"forecast": 194,
"2024-04-2520: 00Z", "to": "2024-04-25T20:30Z", "intensity": {"forecast": 195, "actual": null, "index": "high"3}, ("from": "2024-04-25T20:30Z",
"actual": null, "index": "high")}, ("from":
"2024-04-25T21:00Z", "intensity": ("forecast":
198, "actual": null, "index": "high"'), ("from": "2024-04-25T21: 002",
"2024-04-25T22: 00Z", "intensity": {"forecast": 187, "actual": null,
"to": "2024-04-25T21: 30Z", "intensity": {"forecast": 196,
'actual": null,
"index": "high"}}, {"from": "2024-04-25T21:302"
"to"
"index": "moderate"}}, ("from": "2024-04-25T22:00Z", "to":
"2024-04-25T22: 30Z",
"intensity": ("forecast": 181, "actual": null,
"index": "moderate"}}, {"from": "2024-04-25T22:30Z", "to": "2024-04-25T23:002", "intensity": ("forecast": 180, "actual": null,
"index'
moderate"｝｝，｛"from"：
25T23:30Z", "intensity": {"forecast": 172, "actual": null, "index": "moderate"}}, {"from": "2024-04-25T23: 30Z",
"2024-04-25T23:002",
"to":
" 2024-04-
"moderate"}}, {"from": "2024-04-26T00:00Z", "to": "2024-04-2600: 30Z", "intensity": ("forecast": 150,
"to": "2024-04-2600: 00Z",
"intensity": ("forecast": 150,
"actual": null,
"index":
"actual": null, "index": "moderate")}, ("from": "2024-04-26T00: 302",
"to": "2024-04-26T01:00Z"
"intensity": {"forecast": 149,
"actual": null,
"index": "moderate"}}, ("from": "2024-04-26T01:002",
"to": "2024-04-26T01:30Z", "intensity": {"forecast": 149,
"actual": null,
"index":
"moderate"}}, ...&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Thank you very much&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 26 Apr 2024 09:16:44 GMT</pubDate>
    <dc:creator>anissabnk</dc:creator>
    <dc:date>2024-04-26T09:16:44Z</dc:date>
    <item>
      <title>Rex command help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Rex-command-help/m-p/685596#M233932</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I need your help with a field extraction.&lt;BR /&gt;I have this type of data, and I'd like to extract the following fields with a rex command:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="anissabnk_0-1714121324502.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/30577i1E19D4A119F2DCBC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="anissabnk_0-1714121324502.png" alt="anissabnk_0-1714121324502.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The syntax is as follows :&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;("data": ["from" :
"2024-04-25T11: 30Z",
"to": "2024-04-2512:00Z",
"intensity": ("forecast": 152,
"actual": null, "index": "moderate"}), ("from": "2024-04-25T12:002",
"intensity": {"forecast": 152, "actual": null, "index": "moderate"}), ("from": "2024-04-25T12:30Z",
"to":
{"from": "2024-04-25T13:00Z", "to":
"2024-04-25T12: 30Z",
("forecast": 164,
"actual": null,
"2024-04-2513: 30Z", "intensity": ("forecast": 154,
"to": "2024-04-25T13: 002",
"intensity": ("forecast": 154,
"actual": null,
"index":
"actual": null, "index": "moderate"}), ("from": "2024-04-25T13:30Z*, "to": "2024-04-25T14:002",
"moderate"}},
"intensity"：
04-25T14: 30Z",
"to" :
"index": "moderate"3}, ("from": "2024-04-25T14:002*, "to": "2024-04-25T14:30Z", "intensity": ("forecast": 166, "actual": null, "index": "moderate"}), ("from":
" 2024-04-25T15:00Z"
"actual": nu11,
"index"
"intensity": {"forecast": 170, "actual": null, "index": "moderate"}), {"from": "2024-04-2515: 00Z",
2024-
"to" :
"moderate"}), {"from": "2024-04-25T15:30Z", "to": "2024-04-25T16:00Z", "intensity": ("forecast": 175,
"to": "2024-04-25T15: 30Z",
"intensity": {"forecast": 172,
"2024-04-25T16: 30Z",
"index": "moderate"}}, ("from": "2024-04-25T17:00Z", "to":
"intensity": ("forecast": 177, "actual": null, "index": "moderate"?), ("from": "2024-04-2516: 302",
"actual" : nu11,
"index"
"moderate"}}, ("from": "2024-04-2516: 00Z",
"to": "2024-04-25T17:002",
"intensity": ("forecast": 179,
"actual": null,
2024-04-2517: 30Z", "intensity": ("forecast": 181, "actual": null,
25T18:00Z", "intensity": ("forecast": 184,
"index": "moderate"}}, {"from": "2024-04-25T17: 30Z",
"actual": null, "index": "moderate"}), ("from": "2024-04-25T18:002", "to": "2024-04-25T18: 30Z",
"to": "2024-04-
"moderate"}}, ("from": "2024-04-2518: 30Z", "to": "2024-04-25T19:002",
"intensity": ("forecast": 187, "actual": null,
"intensity": ("forecast": 190,
"actua1": nul1,
"index":
"index":
"high"}}, ("from":
"intensity": {"forecast": 193,
"actual": null, "index":
"2024-04-25T19: 00Z", "to":
"2024-04-25T19: 30Z"
"high"}}, ("from": "2024-04-25T19:30Z", "to": "2024-04-25T20:00Z", "intensity":
{"forecast": 194,
"2024-04-2520: 00Z", "to": "2024-04-25T20:30Z", "intensity": {"forecast": 195, "actual": null, "index": "high"3}, ("from": "2024-04-25T20:30Z",
"actual": null, "index": "high")}, ("from":
"2024-04-25T21:00Z", "intensity": ("forecast":
198, "actual": null, "index": "high"'), ("from": "2024-04-25T21: 002",
"2024-04-25T22: 00Z", "intensity": {"forecast": 187, "actual": null,
"to": "2024-04-25T21: 30Z", "intensity": {"forecast": 196,
'actual": null,
"index": "high"}}, {"from": "2024-04-25T21:302"
"to"
"index": "moderate"}}, ("from": "2024-04-25T22:00Z", "to":
"2024-04-25T22: 30Z",
"intensity": ("forecast": 181, "actual": null,
"index": "moderate"}}, {"from": "2024-04-25T22:30Z", "to": "2024-04-25T23:002", "intensity": ("forecast": 180, "actual": null,
"index'
moderate"｝｝，｛"from"：
25T23:30Z", "intensity": {"forecast": 172, "actual": null, "index": "moderate"}}, {"from": "2024-04-25T23: 30Z",
"2024-04-25T23:002",
"to":
" 2024-04-
"moderate"}}, {"from": "2024-04-26T00:00Z", "to": "2024-04-2600: 30Z", "intensity": ("forecast": 150,
"to": "2024-04-2600: 00Z",
"intensity": ("forecast": 150,
"actual": null,
"index":
"actual": null, "index": "moderate")}, ("from": "2024-04-26T00: 302",
"to": "2024-04-26T01:00Z"
"intensity": {"forecast": 149,
"actual": null,
"index": "moderate"}}, ("from": "2024-04-26T01:002",
"to": "2024-04-26T01:30Z", "intensity": {"forecast": 149,
"actual": null,
"index":
"moderate"}}, ...&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Thank you very much&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 09:16:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Rex-command-help/m-p/685596#M233932</guid>
      <dc:creator>anissabnk</dc:creator>
      <dc:date>2024-04-26T09:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: Rex command help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Rex-command-help/m-p/685599#M233933</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231839"&gt;@anissabnk&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;this seems to be a json format, you could use INDEXED_EXTRACTIONS=json or the spath command&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.2.1/SearchReference/Spath" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/9.2.1/SearchReference/Spath&lt;/A&gt;&lt;/P&gt;&lt;P&gt;If anyway you want to use a regex, you should use more regexes like the following:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex "from\"\s*:\s*\"(?&amp;lt;from&amp;gt;[^\"]+)\""&lt;/LI-CODE&gt;&lt;P&gt;that you can test at&amp;nbsp;&lt;A href="https://regex101.com/r/6NQsEb/1" target="_blank"&gt;https://regex101.com/r/6NQsEb/1&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex "to\"\s*:\s*\"(?&amp;lt;to&amp;gt;[^\"]+)\""&lt;/LI-CODE&gt;&lt;P&gt;that you can test at&amp;nbsp;&lt;A href="https://regex101.com/r/6NQsEb/2" target="_blank"&gt;https://regex101.com/r/6NQsEb/2&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex "intensity\"\s*:\s*\(\"\w+\"\s*:\s*(?&amp;lt;intensity&amp;gt;\d+)"&lt;/LI-CODE&gt;&lt;P&gt;that you can test at&amp;nbsp;&lt;A href="https://regex101.com/r/6NQsEb/3" target="_blank"&gt;https://regex101.com/r/6NQsEb/3&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 09:07:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Rex-command-help/m-p/685599#M233933</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2024-04-26T09:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: Rex command help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Rex-command-help/m-p/685600#M233934</link>
      <description>&lt;P&gt;Please can you repost your sample data in the correct format as what you posted does not match the structure show in your screen grab and is not valid JSON. Also, please paste into a code block &amp;lt;/&amp;gt; to preserve format information.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 09:12:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Rex-command-help/m-p/685600#M233934</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-04-26T09:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: Rex command help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Rex-command-help/m-p/685661#M233950</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;Hello,I have this type of data, and I'd like to extract the following fields with a rex command:&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Two words: Don't. &amp;nbsp;The data you show is clearly a fragment from a JSON object. &amp;nbsp;Do not treat structured data such as JSON as text because the developer can change format at any time without changing syntax and render your rex useless. &amp;nbsp;Splunk has robust, QA-tested commands like &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath" target="_blank" rel="noopener"&gt;spath&lt;/A&gt;. &amp;nbsp;Follow&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;'s advice to share valid, raw JSON data. (Anonymize as needed.) &amp;nbsp;If your raw data is a mix of free text and JSON, show examples of how they are mixed so we can extract the valid JSON, then handle JSON in spath or fromjson (9.0+)&lt;/P&gt;&lt;P&gt;Specific questions:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I have a strong suspicion that your data illustration is not a faithful representation of raw data. &amp;nbsp;Because it contains lots of parentheses "(", ")", instead of curly brackets "{" and "}" as in compliant JSON. It is almost impossible for a developer to make this kind of mistake to mix parentheses and curly brackets randomly. &amp;nbsp;Can you verify and clarify?&lt;/LI&gt;&lt;LI&gt;If your raw event is pure JSON, your highlighted snippets should have already been extracted by Splunk as multivalued data{}.from, data{}.to, data{}.intensity.forecast. &amp;nbsp;Do you not get those?&lt;/LI&gt;&lt;LI&gt;Alternatively, is that illustrated data from a field that is already extracted (but misrepresented with mixed parentheses and curly brackets)?&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Lastly, in a common logging practice is to append JSON data at the end, following some other informational strings that do not contain opening curly bracket. &amp;nbsp;If this is the case, you can easily extract that JSON part with the following and handle it robustly with spath:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex "^[^{]*(?&amp;lt;json_data&amp;gt;.+)"
| spath input=json_data path=data{}
| mvexpand data{}
| spath input=data{}&lt;/LI-CODE&gt;&lt;P&gt;After this, your highlighted values would be in fields from, to, and intensity.forecast, respectively.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 16:56:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Rex-command-help/m-p/685661#M233950</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-04-26T16:56:07Z</dc:date>
    </item>
  </channel>
</rss>

