pyspark.sql.functions.instr(str, substr)[source]

Locate the position of the first occurrence of substr column in the given string. Returns null if either of the arguments are null.

New in version 1.5.0.


The position is not zero based, but 1 based index. Returns 0 if substr could not be found in str.

>>> df = spark.createDataFrame([('abcd',)], ['s',])
>>>, 'b').alias('s')).collect()