<?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: Extracting first and last pattern from a string using regex in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-first-and-last-pattern-from-a-string-using-regex/m-p/550255#M37990</link>
    <description>&lt;P&gt;Many ways to do it, here's another one:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval noTrip = "^never|pull|push$" 
| eval Stops=".madrid-plane.taxi$tour.Home&amp;amp;depart push pull never" 
| makemv delim=" " Stops | mvexpand Stops
| rex field=Stops "(?&amp;lt;First_Stop&amp;gt;\.[^\.]+)\.[^\.]+\.(?&amp;lt;Last_Stop&amp;gt;.+)" 
| eval First=if(match(Stops, noTrip), Stops, First_Stop) 
| eval Last=if(match(Stops, noTrip), "N/A", Last_Stop) 
| fields Stops, First, Last&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first four lines are there to generate some test data, so you can run this search without pulling actual data. Here's what it should produce:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2021-05-03 at 10.48.43 AM.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/14019i1E4B5E6C536CA812/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2021-05-03 at 10.48.43 AM.png" alt="Screen Shot 2021-05-03 at 10.48.43 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Happy Splunking! &lt;/P&gt;</description>
    <pubDate>Mon, 03 May 2021 20:06:42 GMT</pubDate>
    <dc:creator>s2_splunk</dc:creator>
    <dc:date>2021-05-03T20:06:42Z</dc:date>
    <item>
      <title>Extracting first and last pattern from a string using regex</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-first-and-last-pattern-from-a-string-using-regex/m-p/550235#M37984</link>
      <description>&lt;P&gt;Hello People I hope everyone is doing just fine,&lt;/P&gt;&lt;P&gt;I have been trying to extract some values from a field without any luck. I work for a hotel company and whenever a customer uses our transportation services a field named "travel_stops" is recorded and updated. This field due to the way is "programmed" will always come in the following format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;.Madrid-plane.taxi$comp$uber.domestic$depart &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please note that the string will always start with a dot (.)&lt;/P&gt;&lt;P&gt;in other words every "stop" is separated by a (.) dot I want to be able to extract for each value in this field the first and last stops which for this case will be &lt;STRONG&gt;Madrid-plane&lt;/STRONG&gt; and &lt;STRONG&gt;domestic$depart&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I am trying to use something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=Stops "(?&amp;lt;First_Stop&amp;gt;[^.]+).(?&amp;lt;Last_Stop&amp;gt;.+)"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also have another "setback" and it if when a custumer is awaiting his/her first transportation service, dependiong on the type of custumer the system may record something like "awaiting","push","never" ect.. and in those cases I want to be able to leave that record as it is... since I will be doing some extra work on those fiedls..&lt;BR /&gt;&lt;BR /&gt;What I want:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="52.43010752688173%"&gt;travel_stops&lt;/TD&gt;&lt;TD width="14.236559139784946%"&gt;First_Stop&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;Last_Stop&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="52.43010752688173%"&gt;.Madrid-plane.taxi$comp$uber.domestic$depart&lt;/TD&gt;&lt;TD width="14.236559139784946%"&gt;Madrid-plane&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;domestic$depart&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="52.43010752688173%"&gt;never&lt;/TD&gt;&lt;TD width="14.236559139784946%"&gt;never&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;null&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;pull&lt;/TD&gt;&lt;TD&gt;pull&lt;/TD&gt;&lt;TD&gt;null&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;BR /&gt;but is not givving me the expected result thank you for much to anyone who is willing to help me out! Like I truly appreciate it. also, if you have a have a link to a blog on regex in Splunk that will be so much appreciated as I will be using more of these in the future&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Kindly,&lt;/P&gt;&lt;P&gt;Cindy!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 16:39:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-first-and-last-pattern-from-a-string-using-regex/m-p/550235#M37984</guid>
      <dc:creator>cindygibbs_08</dc:creator>
      <dc:date>2021-05-03T16:39:02Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting first and last pattern from a string using regex</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-first-and-last-pattern-from-a-string-using-regex/m-p/550238#M37985</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/233702"&gt;@cindygibbs_08&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;please try this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rx field=MenuFinal "(?&amp;lt;First_Stop&amp;gt;\.[^\.]+)\.[^\.]+\.(?&amp;lt;Last_Stop&amp;gt;.+)"&lt;/LI-CODE&gt;&lt;P&gt;that you can test at&amp;nbsp;&lt;A href="https://regex101.com/r/imkXTy/1" target="_blank"&gt;https://regex101.com/r/imkXTy/1&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 16:04:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-first-and-last-pattern-from-a-string-using-regex/m-p/550238#M37985</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2021-05-03T16:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting first and last pattern from a string using regex</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-first-and-last-pattern-from-a-string-using-regex/m-p/550247#M37986</link>
      <description>&lt;P&gt;Ciao caro grazie mille per il tuo aiuto!.. excuse my italian... I am using your code but then I have values like "awaiting" or "pull" is giving me nothing....&lt;BR /&gt;&lt;BR /&gt;Thank you for your help I have a question what would change if the delimitator character will be a "?" question mark...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 16:46:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-first-and-last-pattern-from-a-string-using-regex/m-p/550247#M37986</guid>
      <dc:creator>cindygibbs_08</dc:creator>
      <dc:date>2021-05-03T16:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting first and last pattern from a string using regex</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-first-and-last-pattern-from-a-string-using-regex/m-p/550249#M37987</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/233702"&gt;@cindygibbs_08&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;thank you for you&amp;nbsp;greetings in Italian!&lt;/P&gt;&lt;P&gt;Anyway, if you could share a sample for each case I could better analyze your needs.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 16:56:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-first-and-last-pattern-from-a-string-using-regex/m-p/550249#M37987</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2021-05-03T16:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting first and last pattern from a string using regex</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-first-and-last-pattern-from-a-string-using-regex/m-p/550252#M37988</link>
      <description>&lt;P&gt;OMG thank you so much!&lt;/P&gt;&lt;P&gt;I want to be able to extract the first stops and the last stop for each costumer in the hotel agency.&lt;BR /&gt;&lt;BR /&gt;The values look like this:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;.madrid-plane.taxi$tour.Home&amp;amp;depart &lt;/LI-CODE&gt;&lt;P&gt;as you can see they are separated by a comma, but I want to be able to extract only the first and last so for my laste example I would get&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;first=madrid-plane 
last=Home&amp;amp;depart &lt;/LI-CODE&gt;&lt;P&gt;but sometimes the values in the field can look like this:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;pull
push
never&lt;/LI-CODE&gt;&lt;P&gt;since they dont have a comma.. or anything such as I would just like them to remain as they are...s basically I want a table like this&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;Stops&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;First&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;Last&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="47px"&gt;.madrid-plane.taxi$tour.Home&amp;amp;depart&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="47px"&gt;madrid-plane&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="47px"&gt;Home$depart&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;pull&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;pull&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;N.A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;push&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;push&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;N.A&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Grazie mille mio amato amico&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 17:11:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-first-and-last-pattern-from-a-string-using-regex/m-p/550252#M37988</guid>
      <dc:creator>cindygibbs_08</dc:creator>
      <dc:date>2021-05-03T17:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting first and last pattern from a string using regex</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-first-and-last-pattern-from-a-string-using-regex/m-p/550253#M37989</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/233702"&gt;@cindygibbs_08&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;if you have so different situations, you could try to use two regexes and the eval command, something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=MenuFinal "(?&amp;lt;First_Stop&amp;gt;\.[^\.]+)\.[^\.]+\.(?&amp;lt;Last_Stop&amp;gt;.+)"
| rex field=MenuFinal "^(?&amp;lt;First_Stop1&amp;gt;\w+)(\.|$)"
| eval 
     First_Stop=coalesce(First_Stop,First_Stop1), 
     Last_Stop=if(isnull(Last_Stop),"N.A:", Last_Stop)&lt;/LI-CODE&gt;&lt;P&gt;have a good evening&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 17:22:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-first-and-last-pattern-from-a-string-using-regex/m-p/550253#M37989</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2021-05-03T17:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting first and last pattern from a string using regex</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-first-and-last-pattern-from-a-string-using-regex/m-p/550255#M37990</link>
      <description>&lt;P&gt;Many ways to do it, here's another one:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval noTrip = "^never|pull|push$" 
| eval Stops=".madrid-plane.taxi$tour.Home&amp;amp;depart push pull never" 
| makemv delim=" " Stops | mvexpand Stops
| rex field=Stops "(?&amp;lt;First_Stop&amp;gt;\.[^\.]+)\.[^\.]+\.(?&amp;lt;Last_Stop&amp;gt;.+)" 
| eval First=if(match(Stops, noTrip), Stops, First_Stop) 
| eval Last=if(match(Stops, noTrip), "N/A", Last_Stop) 
| fields Stops, First, Last&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first four lines are there to generate some test data, so you can run this search without pulling actual data. Here's what it should produce:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2021-05-03 at 10.48.43 AM.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/14019i1E4B5E6C536CA812/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2021-05-03 at 10.48.43 AM.png" alt="Screen Shot 2021-05-03 at 10.48.43 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Happy Splunking! &lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 20:06:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-first-and-last-pattern-from-a-string-using-regex/m-p/550255#M37990</guid>
      <dc:creator>s2_splunk</dc:creator>
      <dc:date>2021-05-03T20:06:42Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting first and last pattern from a string using regex</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-first-and-last-pattern-from-a-string-using-regex/m-p/550258#M37991</link>
      <description>&lt;P&gt;this is amazing thank you so much so so much&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 18:05:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-first-and-last-pattern-from-a-string-using-regex/m-p/550258#M37991</guid>
      <dc:creator>cindygibbs_08</dc:creator>
      <dc:date>2021-05-03T18:05:37Z</dc:date>
    </item>
  </channel>
</rss>

