<?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>question Re: alternative or substitute of REGEXP_INSTR function in Hadoop Hive in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/alternative-or-substitute-of-REGEXP-INSTR-function-in-Hadoop/m-p/175344#M137603</link>
    <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/77272/suhagpandya.html" nodeid="77272"&gt;@Suhag Pandya&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You can use&lt;STRONG&gt; instr function&lt;/STRONG&gt; in hive to return the first occurance of the substring in your string.&lt;/P&gt;&lt;PRE&gt;select instr(string str, string substr);&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Example:-&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;hive&amp;gt; select instr('foobar','o'); //returns first position of o in foobar string
+------+--+
| _c0  |
+------+--+
| 2    |
+------+--+&lt;/PRE&gt;&lt;P&gt;To return the first position of the substring from nth position in your string then use &lt;STRONG&gt;locate function in hive&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Example:-&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;hive&amp;gt; select locate('o','fooobar',4);//returns the first occurance from 4th position 
+------+--+
| _c0  |
+------+--+
| 4    |
+------+--+&lt;/PRE&gt;&lt;P&gt;For &lt;STRONG&gt;case insensitive&lt;/STRONG&gt; use&lt;STRONG&gt; lower function with locate&lt;/STRONG&gt; function&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Example:-&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;hive&amp;gt; select locate('o',lower('FOOOBAR'),4);
+------+--+
| _c0  |
+------+--+
| 4    |
+------+--+&lt;/PRE&gt;&lt;P&gt;There is no built in function that can gives your nth occurrence and match regex of the substr in hive yet, but you can create UDF for this functionality in hive.&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;P&gt;If the Answer addressed your question, &lt;STRONG&gt;Click on Accept button below to accept the answer,&lt;/STRONG&gt; That would be great help to Community users to find solution quickly for these kind of issues.&lt;/P&gt;</description>
    <pubDate>Wed, 02 May 2018 06:27:30 GMT</pubDate>
    <dc:creator>Shu_ashu</dc:creator>
    <dc:date>2018-05-02T06:27:30Z</dc:date>
  </channel>
</rss>

