Search notes:

JavaScript: Find the position of regular expression in a string with search()

String.search returns the (character) position of the (first) matched regular expression.
<!DOCTYPE html>
<html>
<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  <title>String.search()</title>

  <script type="text/javascript">
    
    function main() {

      reNum = /\d/; // Search for a number

      str = 'foo 42 bar';

      posFirstNum = str.search(reNum);
      
      var out = document.getElementById('out');

      out.innerHTML = "The position of the first number in <b>" + str + "</b> is: " + posFirstNum;

    }

  </script>

</head>
<body onload='main()';>
  <div id="out"></div>
</body>
</html>
Github repository about-javascript, path: /objects/String/search.html

See also

match(…) returns an array of matched strings.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758204443, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/JavaScript/objects/String/regular-expression/search(69): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78