The search task takes a regular expression and a string, then searches for the first match of the expression within the string. The task returns the index (position) where a match is found — indexing starts at zero. If no match is found, the task returns -1.
Use search to check whether a certain pattern exists in a string and to find its position. In conjunction with the substr method, you can use search to find and replace text in a data record.
In this example:
str is statically set to Hello World.regexp is or.index result is 7, indicating the pattern "or" is located at position 7 in the string.

In this example:
str is Hey Dr. Livingstone.regexp is \., a special character class notation indicating the match should be a period (.).index result is 6, indicating the period is located at position 6 in the string.For more information, see Using character classes in regular expressions on MDN.


In this example:
str is Hey Judey.regexp is \., indicating the match should be a period.index result is -1.
