<?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: Regular Expression extract beginning and end of string- What am I missing? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-extract-beginning-and-end-of-string-What-am-I/m-p/587594#M204627</link>
    <description>&lt;UL&gt;&lt;LI&gt;I can't help but noticing that your initial regex contains hard-coded leading string "ABC". &amp;nbsp;This implies that the first group of letters is fixed. &amp;nbsp;If this is the case, you can focus on the end of string, then compose with the known group, like this:&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=comment "\bABC-\S+-(?&amp;lt;ABC&amp;gt;\d+)"
| eval ABC="ABC-" . ABC&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Another way is to use sed mode to strip whatever you don't need. &amp;nbsp;This example assumes that leading string is unknown.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=comment mode=sed "s/.*?(\w+)\S+-(\d+).*/\1-\2/"​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(If you cannot sacrifice original content of &lt;FONT face="courier new,courier"&gt;comment&lt;/FONT&gt;, you can first copy it into a different field name such as &lt;FONT face="courier new,courier"&gt;ABC&lt;/FONT&gt;, then apply rex to that field.)&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Alternatively, you can apply sed or &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/TextFunctions#replace.28X.2CY.2CZ.29" target="_blank" rel="noopener"&gt;replace&lt;/A&gt; to the &lt;FONT face="courier new,courier"&gt;ABC&lt;/FONT&gt; field you initially extracted. &amp;nbsp;This example uses replace.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=comment (?&amp;lt;ABC&amp;gt;ABC\-\d+\-\d+\-\d+)
| eval ABC=replace(ABC, "ABC-\d+-\d+-", "ABC-")​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Mar 2022 05:31:20 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2022-03-04T05:31:20Z</dc:date>
    <item>
      <title>Regular Expression extract beginning and end of string- What am I missing?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-extract-beginning-and-end-of-string-What-am-I/m-p/587453#M204587</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a situation where I am trying to pull from within a field the nomenclature of ABC-1234-56-7890 but want to be able to only pull the first three letters and the last four numbers into one field. I have the following query below thus far but have not figured out how to do as described above:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| rex field=comment (?&amp;lt;ABC&amp;gt;ABC\-\d+\-\d+\-\d+)&lt;/LI-CODE&gt;
&lt;P&gt;I want&amp;nbsp;the return of "ABC-7890"&lt;/P&gt;
&lt;P&gt;What am I missing so that I can successfully pull both beginning and end of the above described string? Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 17:36:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-extract-beginning-and-end-of-string-What-am-I/m-p/587453#M204587</guid>
      <dc:creator>rhenry</dc:creator>
      <dc:date>2022-03-03T17:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression extract beginning and end of string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-extract-beginning-and-end-of-string-What-am-I/m-p/587456#M204588</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/243576"&gt;@rhenry&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;you could use a regex and an eval:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;your_search
| rex "^(?&amp;lt;my_field_1&amp;gt;\w\w\w).*(?&amp;lt;myfield_2&amp;gt;\d\d\d\d)"
| eval my_field=my-field-1."-".my_field_2&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you can test the regex at&amp;nbsp;&lt;A href="https://regex101.com/r/S7tXqS/1" target="_blank" rel="noopener"&gt;https://regex101.com/r/S7tXqS/1&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 15:08:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-extract-beginning-and-end-of-string-What-am-I/m-p/587456#M204588</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-03-03T15:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression extract beginning and end of string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-extract-beginning-and-end-of-string-What-am-I/m-p/587457#M204589</link>
      <description>&lt;P&gt;Unfortunately, with PCRE you don't have a "ignore this part" group. (I would also welcome that)&lt;/P&gt;&lt;P&gt;You can however capture the beginning and end into separate fields and then create a calculated field combining them together,&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 15:04:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-extract-beginning-and-end-of-string-What-am-I/m-p/587457#M204589</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-03-03T15:04:40Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression extract beginning and end of string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-extract-beginning-and-end-of-string-What-am-I/m-p/587462#M204590</link>
      <description>&lt;P&gt;Hey this string does what I am looking for. However, it looks like it only works if ABC-1234-56-7890 is the only string in the field. What if there is additional words before and after? Like for example:&lt;/P&gt;&lt;P&gt;"This the location for ABC-1234-56-7890 at this point."&lt;/P&gt;&lt;P&gt;Is there a way to extract just that string highlighted above and again only beginning and end? Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 15:15:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-extract-beginning-and-end-of-string-What-am-I/m-p/587462#M204590</guid>
      <dc:creator>rhenry</dc:creator>
      <dc:date>2022-03-03T15:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression extract beginning and end of string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-extract-beginning-and-end-of-string-What-am-I/m-p/587471#M204591</link>
      <description>&lt;P&gt;Hi, please try this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;your_search
| rex "(?&amp;lt;my_field_1&amp;gt;\w\w\w)\S*(?&amp;lt;myfield_2&amp;gt;\d\d\d\d)"
| eval my_field=my-field-1."-".my_field_2&lt;/LI-CODE&gt;&lt;P&gt;that you can test at&amp;nbsp;&lt;A href="https://regex101.com/r/S7tXqS/2" target="_blank"&gt;https://regex101.com/r/S7tXqS/2&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 15:39:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-extract-beginning-and-end-of-string-What-am-I/m-p/587471#M204591</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-03-03T15:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression extract beginning and end of string- What am I missing?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-extract-beginning-and-end-of-string-What-am-I/m-p/587594#M204627</link>
      <description>&lt;UL&gt;&lt;LI&gt;I can't help but noticing that your initial regex contains hard-coded leading string "ABC". &amp;nbsp;This implies that the first group of letters is fixed. &amp;nbsp;If this is the case, you can focus on the end of string, then compose with the known group, like this:&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=comment "\bABC-\S+-(?&amp;lt;ABC&amp;gt;\d+)"
| eval ABC="ABC-" . ABC&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Another way is to use sed mode to strip whatever you don't need. &amp;nbsp;This example assumes that leading string is unknown.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=comment mode=sed "s/.*?(\w+)\S+-(\d+).*/\1-\2/"​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(If you cannot sacrifice original content of &lt;FONT face="courier new,courier"&gt;comment&lt;/FONT&gt;, you can first copy it into a different field name such as &lt;FONT face="courier new,courier"&gt;ABC&lt;/FONT&gt;, then apply rex to that field.)&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Alternatively, you can apply sed or &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/TextFunctions#replace.28X.2CY.2CZ.29" target="_blank" rel="noopener"&gt;replace&lt;/A&gt; to the &lt;FONT face="courier new,courier"&gt;ABC&lt;/FONT&gt; field you initially extracted. &amp;nbsp;This example uses replace.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=comment (?&amp;lt;ABC&amp;gt;ABC\-\d+\-\d+\-\d+)
| eval ABC=replace(ABC, "ABC-\d+-\d+-", "ABC-")​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 05:31:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-extract-beginning-and-end-of-string-What-am-I/m-p/587594#M204627</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-03-04T05:31:20Z</dc:date>
    </item>
  </channel>
</rss>

