Yahoo Web Search

Search results

      • Using exec () The exec() method is a RegExp expression method. It searches a string for a specified pattern, and returns the found text as an object. If no match is found, it returns an empty (null) object.
      www.w3schools.com/js/js_regexp.asp
  1. People also ask

  2. The exec () method tests for a match in a string. If it finds a match, it returns a result array, otherwise it returns null. Browser Support. exec() is an ECMAScript1 (ES1) feature. ES1 (JavaScript 1997) is fully supported in all browsers: Syntax. RegExpObject.exec (string) Parameter Values. Return Value. More Examples. Example.

    • Try It Yourself

      The W3Schools online code editor allows you to edit code and...

  3. EXEC. The EXEC command is used to execute a stored procedure. The following SQL executes a stored procedure named "SelectAllCustomers":

  4. Oct 13, 2011 · if you use TypeScript you can also install the typings: npm install @types/sqlstring Then use it: import { escape } from 'sqlstring'; const escapedString = escape(`it's going to be escaped!`);

    • Overview
    • Syntax
    • Description
    • Examples
    • Browser compatibility

    The exec() method of RegExp instances executes a search with this regular expression for a match in a specified string and returns a result array, or null.

    Parameters

    str The string against which to match the regular expression. All values are coerced to strings, so omitting it or passing undefined causes exec() to search for the string "undefined", which is rarely what you want.

    Return value

    If the match fails, the exec() method returns null, and sets the regex's lastIndex to 0. If the match succeeds, the exec() method returns an array and updates the lastIndex property of the regular expression object. The returned array has the matched text as the first item, and then one item for each capturing group of the matched text. The array also has the following additional properties: index The 0-based index of the match in the string. input The original string that was matched against. groups A null-prototype object of named capturing groups, whose keys are the names, and values are the capturing groups, or undefined if no named capturing groups were defined. See capturing groups for more information. indices Optional This property is only present when the d flag is set. It is an array where each entry represents the bounds of a substring match. The index of each element in this array corresponds to the index of the respective substring match in the array returned by exec(). In other words, the first indices entry represents the entire match, the second indices entry represents the first capturing group, etc. Each entry itself is a two-element array, where the first number represents the match's start index, and the second number, its end index. The indices array additionally has a groups property, which holds a null-prototype object of all named capturing groups. The keys are the names of the capturing groups, and each value is a two-element array, with the first number being the start index, and the second number being the end index of the capturing group. If the regular expression doesn't contain any named capturing groups, groups is undefined.

    JavaScript RegExp objects are stateful when they have the global or sticky flags set (e.g. /foo/g or /foo/y). They store a lastIndex from the previous match. Using this internally, exec() can be used to iterate over multiple matches in a string of text (with capture groups), as opposed to getting just the matching strings with String.prototype.match().

    When using exec(), the global flag has no effect when the sticky flag is set — the match is always sticky.

    exec() is the primitive method of regexps. Many other regexp methods call exec() internally — including those called by string methods, like @@replace. While exec() itself is powerful (and is the most efficient), it often does not convey the intent most clearly.

    •If you only care whether the regex matches a string, but not what is actually being matched, use RegExp.prototype.test() instead.

    •If you are finding all occurrences of a global regex and you don't care about information like capturing groups, use String.prototype.match() instead. In addition, String.prototype.matchAll() helps to simplify matching multiple parts of a string (with capture groups) by allowing you to iterate over the matches.

    •If you are executing a match to find its index position in the string, use the String.prototype.search() method instead.

    Using exec()

    Consider the following example: The following table shows the state of result after running this script: In addition, re.lastIndex will be set to 25, due to this regex being global.

    Finding successive matches

    If your regular expression uses the g flag, you can use the exec() method multiple times to find successive matches in the same string. When you do so, the search starts at the substring of str specified by the regular expression's lastIndex property (test() will also advance the lastIndex property). Note that the lastIndex property will not be reset when searching a different string, it will start its search at its existing lastIndex. For example, assume you have this script: This script displays the following text: Warning: There are many pitfalls that can lead to this becoming an infinite loop!

    Using exec() with RegExp literals

    You can also use exec() without creating a RegExp object explicitly: This will log a message containing 'hello world!'.

    BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

  5. Using exec() The exec() method is a RegExp expression method. It searches a string for a specified pattern, and returns the found text as an object. If no match is found, it returns an empty (null) object. The following example searches a string for the character "e":

  6. Jul 25, 2024 · Regular expressions are patterns used to match character combinations in strings. In JavaScript, regular expressions are also objects. These patterns are used with the exec() and test() methods of RegExp, and with the match(), matchAll(), replace(), replaceAll(), search(), and split() methods of String.

  7. Definition and Usage. The exec() method tests for a match in a string. This method returns the matched text if it finds a match, otherwise it returns null.

  1. People also search for