<?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: Question for extracting a string out of longer string in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525112#M148146</link>
    <description>&lt;P&gt;Correct. If I did it correctly, this will create a field called 'location'. You could then view a list of 'locations' like so:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| table location&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The 'url' would need to be replaced with whatever field name you have this data stored in.&amp;nbsp;&lt;/P&gt;&lt;P&gt;To handle the 'area' being different, we'd want to vary the ending a little:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=url \\Company\\Segment\\Name\\(?&amp;lt;location&amp;gt;\w+)\\\w+.*&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This will return only what was in the Location portion of your URL. Everything after the `\` would be ignored.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Oct 2020 18:50:18 GMT</pubDate>
    <dc:creator>chaday00</dc:creator>
    <dc:date>2020-10-16T18:50:18Z</dc:date>
    <item>
      <title>Question for extracting a string out of longer string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525087#M148137</link>
      <description>&lt;P&gt;Hello, I am looking to create a new field based on a section from a longer string/web address. I didn't see what i was looking in a search on this site. I assume its possible with a regex but I am not good at those.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are examples of fields I currently have... I am looking to extract the Location part of the string. The Company\Segment\Name does not change before Location. Location will change and is what I need.&amp;nbsp;&lt;/P&gt;&lt;P&gt;\Company\Segment\Name\Location\Area&lt;/P&gt;&lt;P&gt;\Company\Segment\Name\Location\Area&lt;/P&gt;&lt;P&gt;I do not need the Area.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 16:00:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525087#M148137</guid>
      <dc:creator>strehb18</dc:creator>
      <dc:date>2020-10-16T16:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: Question for extracting a string out of longer string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525096#M148140</link>
      <description>&lt;P&gt;Might need a little more information than you provided, but the below may work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=url \\Company\\Segment\\Name\\(?&amp;lt;location&amp;gt;\w+)\\Area&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This assumes the following are static: Company, Segment, Name, Area and creates a new field called 'location'&lt;/P&gt;&lt;P&gt;\w+ means match any word character (i.e.,&amp;nbsp;&lt;SPAN&gt;Matches any letter, digit or underscore. Equivalent to [a-zA-Z0-9_]&lt;/SPAN&gt;), one or more times&lt;/P&gt;&lt;P&gt;You could certainly use regex on the entire string too and only return the location if you wanted.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 16:45:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525096#M148140</guid>
      <dc:creator>chaday00</dc:creator>
      <dc:date>2020-10-16T16:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Question for extracting a string out of longer string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525100#M148141</link>
      <description>&lt;P&gt;I think this is probably very close to what I need. Area is not static however, it will change based on what location is but I won't need that value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, if the field that the original string is in is called location_path. Does that replace "field" or "url" in the above code snippet?&amp;nbsp;&lt;/P&gt;&lt;P&gt;And just so I am clear, that line of code should return what is the "location" part of the string and put it into its own field labeled as location?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 16:55:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525100#M148141</guid>
      <dc:creator>strehb18</dc:creator>
      <dc:date>2020-10-16T16:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: Question for extracting a string out of longer string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525112#M148146</link>
      <description>&lt;P&gt;Correct. If I did it correctly, this will create a field called 'location'. You could then view a list of 'locations' like so:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| table location&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The 'url' would need to be replaced with whatever field name you have this data stored in.&amp;nbsp;&lt;/P&gt;&lt;P&gt;To handle the 'area' being different, we'd want to vary the ending a little:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=url \\Company\\Segment\\Name\\(?&amp;lt;location&amp;gt;\w+)\\\w+.*&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This will return only what was in the Location portion of your URL. Everything after the `\` would be ignored.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 18:50:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525112#M148146</guid>
      <dc:creator>chaday00</dc:creator>
      <dc:date>2020-10-16T18:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: Question for extracting a string out of longer string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525113#M148147</link>
      <description>&lt;P&gt;I get the following error with this but it seems on the verge of working.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;"Error in 'rex' command: Encountered the following error while compiling the regex '\Company': Regex: unrecognized character follows \.&lt;/P&gt;&lt;P&gt;Does this potentially have to do with what actually fills spots between \ has spaces in it?&amp;nbsp;&lt;/P&gt;&lt;P&gt;ex: \Company Name\Segment\Name Name\Location\Area&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 18:45:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525113#M148147</guid>
      <dc:creator>strehb18</dc:creator>
      <dc:date>2020-10-16T18:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: Question for extracting a string out of longer string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525121#M148150</link>
      <description>&lt;P&gt;You have to escape the backslash with another backslash `\\`, this will process the `\` as a literal otherwise it will try to parse \C as a regex expression which it is not.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I forgot the quotes:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=url "\\Company\\Segment\\Name\\(?&amp;lt;location&amp;gt;\w+)\\\w+.*"&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 16 Oct 2020 19:41:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525121#M148150</guid>
      <dc:creator>chaday00</dc:creator>
      <dc:date>2020-10-16T19:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Question for extracting a string out of longer string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525412#M148269</link>
      <description>&lt;P&gt;I think this is close but I think it may be my error. Even with the " " I still get the following error using my actual data. I get myself confused trying to transfer to the data I am actually using. To be clear, I am trying to extract everything between the \ \ where location is.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actual Input (location_path is the field the data is in.)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;| rex field=location_path "\\Oshkosh Corporation\\Defense\\Oshkosh Defense\\(?&amp;lt;location&amp;gt;\w+)\\\w +.*"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;Error Message&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;SPAN&gt;Error in 'rex' command: Encountered the following error while compiling the regex '\Oshkosh Corporation\Defense\Oshkosh Defense\(?&amp;lt;location&amp;gt;\w+)\\w +.*': Regex: unrecognized character follows \.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 16:10:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525412#M148269</guid>
      <dc:creator>strehb18</dc:creator>
      <dc:date>2020-10-19T16:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: Question for extracting a string out of longer string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525416#M148273</link>
      <description>&lt;P&gt;In your 'area' section, it looks like there is&amp;nbsp; a space after the 'w', it should be `\w+.*`&lt;/P&gt;&lt;P&gt;I couldn't find it in the documentation, but you may have to escape the white spaces too. Either way, the last query below, may help.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":crossed_fingers:"&gt;🤞&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=location_path "\\Oshkosh Corporation\\Defense\\Oshkosh Defense\\(?&amp;lt;location&amp;gt;\w+)\\\w+.*"

| rex field=location_path "\\Oshkosh\ Corporation\\Defense\\Oshkosh\ Defense\\(?&amp;lt;location&amp;gt;\w+)\\\w+.*"

\\\w+.*\s\w+.*\\\w+.*\\\w+.*\s\w+.*\\(?&amp;lt;location&amp;gt;\w+)\\\w+.*&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 16:29:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525416#M148273</guid>
      <dc:creator>chaday00</dc:creator>
      <dc:date>2020-10-19T16:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: Question for extracting a string out of longer string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525417#M148274</link>
      <description>&lt;P&gt;I get the same error without the space.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 16:18:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525417#M148274</guid>
      <dc:creator>strehb18</dc:creator>
      <dc:date>2020-10-19T16:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: Question for extracting a string out of longer string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525440#M148287</link>
      <description>&lt;P&gt;I'm not complete sure how your location is configured so I made some assumptions.&lt;/P&gt;&lt;P&gt;First I created a CSV file to test with and then created a lookup table:&lt;/P&gt;&lt;P&gt;location_number, location_path&lt;BR /&gt;1,"\Oshkosh Corporation\Defense\Oshkosh Defense\New York, NY\Staten Island"&lt;BR /&gt;2,"\Oshkosh Corporation\Defense\Oshkosh Defense\Atlanta, GA\Bankhead"&lt;BR /&gt;3,"\Oshkosh Corporation\Defense\Oshkosh Defense\Atlanta, GA\Peachtree Center"&lt;BR /&gt;4,"\Oshkosh Corporation\Defense\Oshkosh Defense\Seattle, WA\Pier"&lt;/P&gt;&lt;P&gt;Then using the query below I was able to get the rex working--turns out I needed 3 backslashes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| inputlookup test_urls.csv | rex field=location_path "\\\Oshkosh Corporation\\\Defense\\\Oshkosh Defense\\\(?&amp;lt;location&amp;gt;\w+.*\,[\sA-Z]{3})" | table location&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" width="25.54%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.33%"&gt;location&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.33%"&gt;New York, NY&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.33%"&gt;Atlanta, GA&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.33%"&gt;Atlanta, GA&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.33%"&gt;Seattle, WA&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 18:32:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525440#M148287</guid>
      <dc:creator>chaday00</dc:creator>
      <dc:date>2020-10-19T18:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: Question for extracting a string out of longer string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525441#M148288</link>
      <description>&lt;P&gt;Yes! This worked for my data. Thank you for all the help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 18:48:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-for-extracting-a-string-out-of-longer-string/m-p/525441#M148288</guid>
      <dc:creator>strehb18</dc:creator>
      <dc:date>2020-10-19T18:48:46Z</dc:date>
    </item>
  </channel>
</rss>

