search in JS
Last updated
Last updated
Finds the index of a pattern using REGEX (JavaScript search function Documentation).
String.search( regex )
regex
: Regular expression which matches with the desired pattern.
Integer. If the pattern does not match with any part of the string, returns -1.
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;