Tag Archive for: string

Split

Splits a s​tring​ into an array of strings, without any JavaScript method at all.

Looking for a string inside another string

If you want to find a string inside another string, there are many options available, each one will depend on the result and performance you are looking for.

  • Use test if you want just to know if the string exists (true) or not (false).
  • Use exec if you want to get the string you are looking for, if the string doesn’t exist you will get nothing (null).
  • Use match if you want to get all the strings that match your string, it works like exec, if you want to get your array of string use g (global) in your regular expression.
  • Use search if you want to get the position of the string you are looking for, if the string doesn’t exist you will get -1.
  • Use indexOf if you want to get the position of the string you are looking for, it works like search but you cannot use regular expressions. indexOf is always sensitive.

Note: All methods can use regular expressions except indexOf.

Here a real example:

Learn regular expressions on: RegexOne and RegExr.