JavaScript Flexibility – Regex match()

Today after two posts [#1, #2] in the past days here’s something that shows again the JavaScript power. This is not a complete example, but it’s good to start.

var str = '/text/1/text/2/';
var a = str.match(/(\d+)/gi);
console.log(a);

in that example you’ll get an array with all the numbers in the string ["1", "2"] – yet another flexible js snippet!

Related posts:

  1. A JavaScript Trick You Should Know
  2. Quick Look at JavaScript Objects
  3. Flexible JavaScript – Splitting Strings
This entry was posted in javascript, micro tutorial and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">