<?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: Regex to extract string from field when characters 5 and 6 match pattern in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-string-from-field-when-characters-5-and-6-match/m-p/583558#M203225</link>
    <description>&lt;P&gt;OK, that's interesting because it doesn't match the example you gave&lt;/P&gt;&lt;P&gt;&lt;A href="https://regex101.com/r/MSD0rq/1" target="_blank"&gt;https://regex101.com/r/MSD0rq/1&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Feb 2022 14:29:42 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2022-02-03T14:29:42Z</dc:date>
    <item>
      <title>Regex to extract string from field when characters 5 and 6 match pattern</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-string-from-field-when-characters-5-and-6-match/m-p/583438#M203168</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a field 'narrative' which contains long strings describing what happened to a piece of equipment.&amp;nbsp; Within that string in various locations, there is a substring that identifies the piece of equipment (Yes, it would be much better to have this as a defined field on its own, no I don't know why the sysadmins set it up this way, I just inherited it).&amp;nbsp; The equipment identifier is a 16 character string, and the 5th and 6th characters are always the state abbreviation (ex. NJ for New Jersey, TX for Texas, etc.).&amp;nbsp; It's not always the first substring within the field, so I can't just count to the first 5:6 characters.&lt;/P&gt;&lt;P&gt;Example: [may or may not be data here] 1234NJ56ABCD1234 [maybe some more data here]&lt;/P&gt;&lt;P&gt;I want to extract that 16 char substring that has a valid state abbreviation into a new field called "equip_id".&amp;nbsp; I've tried rex narrative= "(\d{5}|\w{5})?(?&amp;lt;equip_id&amp;gt;\w{1})" but it is so far failing, and plus I think this would only get the 5th char.&amp;nbsp; Plus I can't figure out where to put in the list of acceptable things to match against.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Feb 2022 18:22:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-string-from-field-when-characters-5-and-6-match/m-p/583438#M203168</guid>
      <dc:creator>andyd</dc:creator>
      <dc:date>2022-02-02T18:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract string from field when characters 5 and 6 match pattern</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-string-from-field-when-characters-5-and-6-match/m-p/583442#M203171</link>
      <description>&lt;P&gt;You could list groups of 2 letter state abbreviations with | between (or operator)&lt;/P&gt;&lt;P&gt;Multiple rex commands are fine as it only sets equip_id if there is a match&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex "\s?(?&amp;lt;equip_id&amp;gt;\w{4}(NJ|TX|CT)\w{10})\s"
| rex "\s?(?&amp;lt;equip_id&amp;gt;\w{4}(NY|MA|CA|WA)\w{10})\s"&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 02 Feb 2022 18:41:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-string-from-field-when-characters-5-and-6-match/m-p/583442#M203171</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-02-02T18:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract string from field when characters 5 and 6 match pattern</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-string-from-field-when-characters-5-and-6-match/m-p/583556#M203224</link>
      <description>&lt;P&gt;Here's what we ended up using:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;rex field=narrative "(?&amp;lt;equip_id&amp;gt;[A-Z]{4}([NY|NJ|TX|OR]{2})[A-Za-z0-9]{10})"&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 14:21:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-string-from-field-when-characters-5-and-6-match/m-p/583556#M203224</guid>
      <dc:creator>andyd</dc:creator>
      <dc:date>2022-02-03T14:21:11Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract string from field when characters 5 and 6 match pattern</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-string-from-field-when-characters-5-and-6-match/m-p/583558#M203225</link>
      <description>&lt;P&gt;OK, that's interesting because it doesn't match the example you gave&lt;/P&gt;&lt;P&gt;&lt;A href="https://regex101.com/r/MSD0rq/1" target="_blank"&gt;https://regex101.com/r/MSD0rq/1&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 14:29:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-string-from-field-when-characters-5-and-6-match/m-p/583558#M203225</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-02-03T14:29:42Z</dc:date>
    </item>
  </channel>
</rss>

