<?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: How can you do OR statements in rex? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-you-do-OR-statements-in-rex/m-p/30710#M6251</link>
    <description>&lt;P&gt;I have a field called "results" that looks like one of the following:&lt;/P&gt;

&lt;P&gt;192.168.250|192.168.250.83|unknown (57753/udp)&lt;/P&gt;

&lt;P&gt;OR&lt;/P&gt;

&lt;P&gt;192.168.250|192.168.250.83|snmp (161/udp)|14274|&lt;/P&gt;

&lt;P&gt;I'm trying to extract the service name and ports, such as "ssh (22/tcp)". Some extractions end with a new line, others with a |. &lt;/P&gt;

&lt;P&gt;My rex is: rex field=results max_match=400 "(?i)\d+.\d+.\d+|\d+.\d+.\d+.\d+|(?P&lt;SERVICE_NAME&gt;[^|]+)&lt;/SERVICE_NAME&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 09:23:35 GMT</pubDate>
    <dc:creator>jambajuice</dc:creator>
    <dc:date>2020-09-28T09:23:35Z</dc:date>
    <item>
      <title>How can you do OR statements in rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-you-do-OR-statements-in-rex/m-p/30708#M6249</link>
      <description>&lt;P&gt;I'm trying to write a regex expression that extracts a field that ends in either a new line or a ":".  I am trying to write the equivalent of (\n|:).  When I use that kind of regex in a transforms.conf or props.conf file, it works fine.  When I use it in a search command, it always treats the "|" OR symbol as a search pipeline.  Is there any way to escape it using rex so that Splunk will treat it like an "OR"?&lt;/P&gt;

&lt;P&gt;Thx.&lt;/P&gt;

&lt;P&gt;Craig&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2011 15:00:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-you-do-OR-statements-in-rex/m-p/30708#M6249</guid>
      <dc:creator>jambajuice</dc:creator>
      <dc:date>2011-01-24T15:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: How can you do OR statements in rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-you-do-OR-statements-in-rex/m-p/30709#M6250</link>
      <description>&lt;P&gt;The reason Splunk treats the "|" symbol as a search pipeline is most likely because you're not putting your regex inside quotes. You're probably doing something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearch | rex field=_raw (?&amp;lt;yourfield&amp;gt;\n|:)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;whereas you should be doing it like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearch | rex field=_raw "(?&amp;lt;yourfield&amp;gt;\n|:)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Jan 2011 15:30:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-you-do-OR-statements-in-rex/m-p/30709#M6250</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2011-01-24T15:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: How can you do OR statements in rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-you-do-OR-statements-in-rex/m-p/30710#M6251</link>
      <description>&lt;P&gt;I have a field called "results" that looks like one of the following:&lt;/P&gt;

&lt;P&gt;192.168.250|192.168.250.83|unknown (57753/udp)&lt;/P&gt;

&lt;P&gt;OR&lt;/P&gt;

&lt;P&gt;192.168.250|192.168.250.83|snmp (161/udp)|14274|&lt;/P&gt;

&lt;P&gt;I'm trying to extract the service name and ports, such as "ssh (22/tcp)". Some extractions end with a new line, others with a |. &lt;/P&gt;

&lt;P&gt;My rex is: rex field=results max_match=400 "(?i)\d+.\d+.\d+|\d+.\d+.\d+.\d+|(?P&lt;SERVICE_NAME&gt;[^|]+)&lt;/SERVICE_NAME&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 09:23:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-you-do-OR-statements-in-rex/m-p/30710#M6251</guid>
      <dc:creator>jambajuice</dc:creator>
      <dc:date>2020-09-28T09:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: How can you do OR statements in rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-you-do-OR-statements-in-rex/m-p/30711#M6252</link>
      <description>&lt;P&gt;But for some reason when I display the results in a table, the values that do not end with |5 digits| appear as:  unknown(5774/udp) 192.168.250.  So, it looks like it is grabbing the next line up until the "|".  &lt;/P&gt;

&lt;P&gt;How do I tell rex to end the match on either a "|" or a new line character?&lt;/P&gt;

&lt;P&gt;Thx.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2011 16:10:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-you-do-OR-statements-in-rex/m-p/30711#M6252</guid>
      <dc:creator>jambajuice</dc:creator>
      <dc:date>2011-01-24T16:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: How can you do OR statements in rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-you-do-OR-statements-in-rex/m-p/30712#M6253</link>
      <description>&lt;P&gt;Putting the regex in quotes didn't help.  I used the following lookbehind assertion to solve the problem:&lt;/P&gt;

&lt;P&gt;(?&amp;lt;=))&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2011 18:01:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-you-do-OR-statements-in-rex/m-p/30712#M6253</guid>
      <dc:creator>jambajuice</dc:creator>
      <dc:date>2011-01-24T18:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: How can you do OR statements in rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-you-do-OR-statements-in-rex/m-p/30713#M6254</link>
      <description>&lt;P&gt;Lookbehinds are not particularly performant. Why not define your regex such as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"\|(?&amp;lt;service_name&amp;gt;\w+\([^\)]+\))"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;thus terminating the extraction at the closing parenthesis? &lt;/P&gt;

&lt;P&gt;If else, you need a simple choice between one or more single characters, you can use a char class:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[\n:]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;matches either a new line or a column. &lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2011 21:45:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-you-do-OR-statements-in-rex/m-p/30713#M6254</guid>
      <dc:creator>Paolo_Prigione</dc:creator>
      <dc:date>2011-01-24T21:45:06Z</dc:date>
    </item>
  </channel>
</rss>

