<?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: Replacing part of string when it's equal to a field value in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316779#M94776</link>
    <description>&lt;P&gt;Thank you all for quick replies! Ok, this is it (I have to replace letters with x)"&lt;/P&gt;

&lt;P&gt;myfield="From: Smith, John xxxx Sent: Thursday, April 13, 2017 9:38 AM To: xxxxxxx, xxxxxxxxxxxxx  xxxxxxxxxxx  Subject: yyyyyyyyyyyyyyyyyyyy yyyyyyyyyyyyyy yyyyyyyyyyy yyyyyyyyyyyy yyyyyyyyyyyy yyyyyyyyyyyyy yyyyyyyy yyyyyyyy yyyyyyyyyyy yyyyyyyyyyy yyyyyyyyyyy yy yyy yyyyyyy yy yyyyyyyy yyy yyyyy yyy yyyyyyyy xxxx xx xxxx John xxxxxxxxxx xxxxxxxx xxxxxxxx xxxx"&lt;/P&gt;

&lt;P&gt;name="John"&lt;/P&gt;

&lt;P&gt;Value of &lt;EM&gt;name&lt;/EM&gt; changes but is always included in the text. I need everything between words "Subject:" and name (here being "John").&lt;BR /&gt;
I really hope I made it clear this time.&lt;/P&gt;</description>
    <pubDate>Thu, 25 May 2017 08:42:19 GMT</pubDate>
    <dc:creator>mszopa</dc:creator>
    <dc:date>2017-05-25T08:42:19Z</dc:date>
    <item>
      <title>Replacing part of string when it's equal to a field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316773#M94770</link>
      <description>&lt;P&gt;Hi!&lt;BR /&gt;
I have fields myfield and name which contains text of an email going like this:&lt;/P&gt;

&lt;P&gt;Example1:&lt;BR /&gt;
myfield="From: Smith, John Sent: Thursday, April 13, 2017 9:38 AM To: xxxxxxxxx xxxxxx   Subject: yyyyyyyy yyyy yyy yy yyyyy yyyy yyyyyy yy yyyyy yyy yyyyyyy yyyy y yyyyyyyy yy yyyy yyyyyyyyy yy yyyy yyyy yyyyyyyyyy yyyyy yyy yyyyyyy yyyyyyyyyyyyy yyyy yyy yyyy yy yyyyyyy yyyyyyyyyy yy yyyyyyy John xxxxxx xxxxxxx xxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxx xxxxxx xxxxx xxxxxxxx xxxx xx"&lt;BR /&gt;
name="John"&lt;/P&gt;

&lt;P&gt;Example2:&lt;BR /&gt;
"From: Sue, Peggy Sent: Tuesday, April 18, 2017 4:48 PM To: xxxx xxxxx  Subject: yyyyyyyyy yyyyyyyyy yyyyyyyyyyyyy yyyyyy yyyyyyyyy yyyyyyyyyyy yyyyyyyyyy yyyyyyyyyy yyyyyyyyyy yyyyyyyyyyy yyyyyyyyyyyyyyy yyy yyyyyyyyy yyyyyyyyyyyy yyyyyyyyyyyyy yyyyyyyyyyyy yyyyyyyyyyy yyyyyyyyyyyyy yyyy yyyy y yyyy yyyy yyyyyyyy Peggy xxxx xxxxxxxx xxxx xxxxxx xx xxxxxx xxxxxxxxx xxxxxxx xxxxxxxx xxx"&lt;BR /&gt;
name="Peggy"&lt;/P&gt;

&lt;P&gt;so name is different in each email but always appears. I want to extract all the Ys. I tried using rex, but since name is not a static text but changes for each event, i didn't work. There are no specific characters that I could try using, the only constant thing is that name appears.  Any ideas how I could do that?&lt;/P&gt;

&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2017 14:42:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316773#M94770</guid>
      <dc:creator>mszopa</dc:creator>
      <dc:date>2017-05-24T14:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing part of string when it's equal to a field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316774#M94771</link>
      <description>&lt;P&gt;Hi mszopa,&lt;BR /&gt;
could you share an example of your logs?&lt;BR /&gt;
Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2017 15:33:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316774#M94771</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2017-05-24T15:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing part of string when it's equal to a field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316775#M94772</link>
      <description>&lt;P&gt;@mszopa... it would be better if you can mock some sample events. However, in the existing sample that you have provided if sometext2 always exists after &lt;CODE&gt;Subject:&lt;/CODE&gt; and before an email address you can use email address  regular expression as your end pattern i.e.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Subject:\s(?&amp;lt;sometext2&amp;gt;.*)\s([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please add sample events if you can, I have used following dummy data (Assuming single space between Subject: and sometext2 and sometext2 and Sender as per your Question):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; Subject: My Test Email to abc123@mymail.com
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 May 2017 15:52:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316775#M94772</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-05-24T15:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing part of string when it's equal to a field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316776#M94773</link>
      <description>&lt;P&gt;Sorry, i could have been more specific from the start!&lt;/P&gt;

&lt;P&gt;It's something like that:&lt;BR /&gt;
""From: Smith, John Sent: Monday, May 08, 2017 3:11 PM To: Receiver's_email@address Subject: &lt;EM&gt;Something's not working Dear all, could you please help me with this issue? [problem description] &lt;BR /&gt;
Thanks&lt;/EM&gt; &lt;STRONG&gt;John Smith&lt;/STRONG&gt; [workplace, etc]"&lt;/P&gt;

&lt;P&gt;So the "Subject:" and "Name Last Name" always appear but the name changes. While getting regular expression starting from Subject is simple, I don't know how to remove everything after the name.&lt;BR /&gt;
I also have a field called "sender" which here would be sender="John Smith" so I thought about using it.&lt;/P&gt;

&lt;P&gt;All the best, &lt;BR /&gt;
Magda&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2017 16:02:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316776#M94773</guid>
      <dc:creator>mszopa</dc:creator>
      <dc:date>2017-05-24T16:02:56Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing part of string when it's equal to a field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316777#M94774</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "Subject:\s+(?&amp;lt;Subject&amp;gt;.*?)\s+Sender:?\s+[^@]+@"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 May 2017 16:13:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316777#M94774</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-05-24T16:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing part of string when it's equal to a field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316778#M94775</link>
      <description>&lt;P&gt;@mszopa, it is best you provide 2 things, 2 raw events, and part of the text you want to extract on each. I red question and comments twice and still not clear what you are looking for.&lt;BR /&gt;
Is this a multi line regex or single line?&lt;BR /&gt;
what changes clearly in your event, does problem description always starts with "[" or in the next line. &lt;BR /&gt;
if you are trying to be careful on information to share, replace messages with xxxxx and yyyy s to make clear. you can even replace names as micky mouse etc.. &lt;BR /&gt;
Also, which name, the one starts with lastname, firstname or the one at the end of the event. &lt;BR /&gt;
If you explain it well, it appears me that your solution resides next to regex lookahead lookbehind, again need a clear info. to provide you something, There is a way you can use your known! sender name in Regex as well.&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2017 20:40:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316778#M94775</guid>
      <dc:creator>akocak</dc:creator>
      <dc:date>2017-05-24T20:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing part of string when it's equal to a field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316779#M94776</link>
      <description>&lt;P&gt;Thank you all for quick replies! Ok, this is it (I have to replace letters with x)"&lt;/P&gt;

&lt;P&gt;myfield="From: Smith, John xxxx Sent: Thursday, April 13, 2017 9:38 AM To: xxxxxxx, xxxxxxxxxxxxx  xxxxxxxxxxx  Subject: yyyyyyyyyyyyyyyyyyyy yyyyyyyyyyyyyy yyyyyyyyyyy yyyyyyyyyyyy yyyyyyyyyyyy yyyyyyyyyyyyy yyyyyyyy yyyyyyyy yyyyyyyyyyy yyyyyyyyyyy yyyyyyyyyyy yy yyy yyyyyyy yy yyyyyyyy yyy yyyyy yyy yyyyyyyy xxxx xx xxxx John xxxxxxxxxx xxxxxxxx xxxxxxxx xxxx"&lt;/P&gt;

&lt;P&gt;name="John"&lt;/P&gt;

&lt;P&gt;Value of &lt;EM&gt;name&lt;/EM&gt; changes but is always included in the text. I need everything between words "Subject:" and name (here being "John").&lt;BR /&gt;
I really hope I made it clear this time.&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 08:42:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316779#M94776</guid>
      <dc:creator>mszopa</dc:creator>
      <dc:date>2017-05-25T08:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing part of string when it's equal to a field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316780#M94777</link>
      <description>&lt;P&gt;Sadly, there is no "@" character, I've only got the name. I put an example in a comment above.&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 08:44:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316780#M94777</guid>
      <dc:creator>mszopa</dc:creator>
      <dc:date>2017-05-25T08:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing part of string when it's equal to a field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316781#M94778</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval myfield="From: Smith, John Sent: Thursday, April 13, 2017 9:38 AM To: xxxxxxxxx xxxxxx Subject: yyyyyyyy yyyy yyy yy yyyyy yyyy yyyyyy yy yyyyy yyy yyyyyyy yyyy y yyyyyyyy yy yyyy yyyyyyyyy yy yyyy yyyy yyyyyyyyyy yyyyy yyy yyyyyyy yyyyyyyyyyyyy yyyy yyy yyyy yy yyyyyyy yyyyyyyyyy yy yyyyyyy John xxxxxx xxxxxxx xxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxx xxxxxx xxxxx xxxxxxxx xxxx xx
From: Sue, Peggy Sent: Tuesday, April 18, 2017 4:48 PM To: xxxx xxxxx Subject: yyyyyyyyy yyyyyyyyy yyyyyyyyyyyyy yyyyyy yyyyyyyyy yyyyyyyyyyy yyyyyyyyyy yyyyyyyyyy yyyyyyyyyy yyyyyyyyyyy yyyyyyyyyyyyyyy yyy yyyyyyyyy yyyyyyyyyyyy yyyyyyyyyyyyy yyyyyyyyyyyy yyyyyyyyyyy yyyyyyyyyyyyy yyyy yyyy y yyyy yyyy yyyyyyyy Peggy xxxx xxxxxxxx xxxx xxxxxx xx xxxxxx xxxxxxxxx xxxxxxx xxxxxxxx xxx"
| makemv delim="
" myfield
| mvexpand myfield

| rename COMMENT AS "Everything above creates sample data; everything below is your solution"

| rex field=myfield "From:\s*(?:[^,]+,\s*)?(?&amp;lt;name&amp;gt;[^:]+)\s+Sent:\s+"
| eval myportion=split(myfield, name)
| eval myportion=mvindex(myportion, 1)
| rex field=myportion mode=sed "s/^.*? Subject: //"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 May 2017 20:19:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316781#M94778</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-05-25T20:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing part of string when it's equal to a field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316782#M94779</link>
      <description>&lt;P&gt;So simple, now that you wrote it!&lt;BR /&gt;
Thank you very much for your help!&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 17:30:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Replacing-part-of-string-when-it-s-equal-to-a-field-value/m-p/316782#M94779</guid>
      <dc:creator>mszopa</dc:creator>
      <dc:date>2017-05-26T17:30:59Z</dc:date>
    </item>
  </channel>
</rss>

