search in JS

Description

Finds the index of a pattern using REGEX (JavaScript search function Documentation).

Sample Source Pattern

Syntax

String.search( regex )

Arguments

regex: Regular expression which matches with the desired pattern.

Return Type

Integer. If the pattern does not match with any part of the string, returns -1.

Examples

CREATE OR REPLACE FUNCTION get_index_pattern(pattern varchar, str varchar)
  RETURNS float
  LANGUAGE JAVASCRIPT
AS
$$
  function GET_PATTERN(pattern, string){
    return string.search(new RegExp( pattern ));
    }
   return GET_PATTERN(PATTERN, STR) + 1;
$$;

SELECT GET_INDEX_PATTERN('on+', 'No, no, non esistono più') PATINDEX;

Last updated