<?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 to extract area codes from phone number field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117470#M31310</link>
    <description>&lt;P&gt;What if you changed it to:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; rex "1?(?&amp;lt;area_code&amp;gt;\d{3})\d{6}"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 03 Feb 2015 21:31:21 GMT</pubDate>
    <dc:creator>masonmorales</dc:creator>
    <dc:date>2015-02-03T21:31:21Z</dc:date>
    <item>
      <title>How to extract area codes from phone number field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117460#M31300</link>
      <description>&lt;P&gt;Hi. I have a series of systems (contact center, fax, Cisco CUCM, etc) where phone numbers are returned in the data. The phone numbers can be represented by:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;5-digit extension (ie. x22101)&lt;/LI&gt;
&lt;LI&gt;10-digit NANP number (i.e. 3125551212)&lt;/LI&gt;
&lt;LI&gt;11-digit NANP number (ie. 13125551212)&lt;/LI&gt;
&lt;LI&gt;E.164 number  (+13125551212)&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;For the moment, I am not concerned about #1 or #4, but I would like to do two things: Match only callers that have 10 or 11-digit phone numbers, strip the country code "1" when it shows up, and then leave only the area code for area code mapping.&lt;/P&gt;

&lt;P&gt;Has anyone done this?&lt;/P&gt;</description>
      <pubDate>Mon, 02 Feb 2015 20:42:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117460#M31300</guid>
      <dc:creator>jhillenburg</dc:creator>
      <dc:date>2015-02-02T20:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract area codes from phone number field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117461#M31301</link>
      <description>&lt;P&gt;Try a calculated field.&lt;BR /&gt;&lt;BR /&gt;
Settings -&amp;gt; Fields -&amp;gt; Calculated Fields&lt;/P&gt;

&lt;P&gt;if(len(phone_number)==10 or len(phone_number)==11,replace(phone_number, "^1?(\d{3})\d{7}$","\1"))&lt;/P&gt;

&lt;P&gt;You will have to associate it with your target source, sourcetype, or host, as well as the target app.  Might have to mess with the regular expression and matched field length to include the + sign.&lt;/P&gt;

&lt;P&gt;--&lt;BR /&gt;
J.R. Murray&lt;BR /&gt;
MetaNet IVS&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:49:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117461#M31301</guid>
      <dc:creator>jrmurray</dc:creator>
      <dc:date>2020-09-28T18:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract area codes from phone number field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117462#M31302</link>
      <description>&lt;P&gt;If I am understanding what you are after. This is the regex you can use for the field extractor.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; 1?(?&amp;lt;NANP&amp;gt;\d{10}\d?)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Feb 2015 22:24:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117462#M31302</guid>
      <dc:creator>KindaWorking</dc:creator>
      <dc:date>2015-02-02T22:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract area codes from phone number field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117463#M31303</link>
      <description>&lt;P&gt;You know the country code is always 1 (if present)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;                            1?(?&amp;lt;ph_num&amp;gt;\d{10})  ==&amp;gt; This should return 10 digit irrespective whether country code 1 is prefix or not.
                            \d*(?&amp;lt;ph_num&amp;gt;\d{10})  ==&amp;gt; This return last 10 digits from phone number irrespective of whether the country code is 1 or 22 or 100 or not prefixed.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Feb 2015 22:56:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117463#M31303</guid>
      <dc:creator>jayannah</dc:creator>
      <dc:date>2015-02-02T22:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract area codes from phone number field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117464#M31304</link>
      <description>&lt;P&gt;If you are only after the area code for those two scenarios, try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex "1?(?&amp;lt;area_code&amp;gt;\d{3})"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Feb 2015 00:43:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117464#M31304</guid>
      <dc:creator>masonmorales</dc:creator>
      <dc:date>2015-02-03T00:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract area codes from phone number field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117465#M31305</link>
      <description>&lt;P&gt;This is great, except that it matches 5-digit extensions beginning with "1".&lt;/P&gt;</description>
      <pubDate>Tue, 03 Feb 2015 20:51:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117465#M31305</guid>
      <dc:creator>jhillenburg</dc:creator>
      <dc:date>2015-02-03T20:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract area codes from phone number field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117466#M31306</link>
      <description>&lt;P&gt;What I wanted to do was to pull out the area code. I think another responder below has gotten me a lot closer. However, what you have done has solved a related problem. That, I have one system where the logs easily provide me with the telephone number, but another one where I needed to perform field extract, and your regexp might be helpful. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Feb 2015 20:53:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117466#M31306</guid>
      <dc:creator>jhillenburg</dc:creator>
      <dc:date>2015-02-03T20:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract area codes from phone number field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117467#M31307</link>
      <description>&lt;P&gt;Thanks. This seems to be helpful in the same manner as the response from KindaWorking,, above.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Feb 2015 20:55:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117467#M31307</guid>
      <dc:creator>jhillenburg</dc:creator>
      <dc:date>2015-02-03T20:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract area codes from phone number field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117468#M31308</link>
      <description>&lt;P&gt;I'm trying to determine what this gets me that the other responses don't. Thanks for the response.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Feb 2015 20:58:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117468#M31308</guid>
      <dc:creator>jhillenburg</dc:creator>
      <dc:date>2015-02-03T20:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract area codes from phone number field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117469#M31309</link>
      <description>&lt;P&gt;This basically says if the phone number is 10 or 11 digits, perform the regular expression match and preserve only the digits you are looking for.  In your example, a field extractor would probably work just as well, but this gives you a little more flexibility I think.  On second glance, it looks like a character was missing from my initial response, so try this instead: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if(len(phone_number)&amp;gt;=10 and len(phone_number)&amp;lt;=12,replace(phone_number, "^\+?1?(\d{3})\d{7}$","\1"))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will take care of handling the + operator as well.  The field extractor version of this regular expression would be something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;\+?1?(?P&amp;lt;area_code&amp;gt;\d{3})\d{7}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Feb 2015 21:09:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117469#M31309</guid>
      <dc:creator>jrmurray</dc:creator>
      <dc:date>2015-02-03T21:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract area codes from phone number field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117470#M31310</link>
      <description>&lt;P&gt;What if you changed it to:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; rex "1?(?&amp;lt;area_code&amp;gt;\d{3})\d{6}"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Feb 2015 21:31:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-area-codes-from-phone-number-field/m-p/117470#M31310</guid>
      <dc:creator>masonmorales</dc:creator>
      <dc:date>2015-02-03T21:31:21Z</dc:date>
    </item>
  </channel>
</rss>

