Dave's Brain

Browse - Programming Tips - How can I extract using /g in a regular expression in javaScript?

Date: 2016apr18
Language: javaScript

Q.  How can I extract using /g in a regular expression in javaScript?

A.  Here is an example:

var re = /\{([^}]*)\}/g; // {stuff}{stuff}{stuff}... var a; while ((a = re.exec(value)) !== null) { var includingBrace = a[0]; // one full match var insideBrace = a[1]; // characters inside the round brackets }
String.match() doesn't work

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.