Baku Baku - 1 year ago 126
Javascript Question

Javascript regex error, text between two characters


which is matching text:

[11/Sep/2016:21:58:55 +0000]

it works fine in sublime while testing, but when I do


Ive got error:
SyntaxError: Invalid regular expression

what Im doing wrong ?

Answer Source

You can use regex as :/[^\[\]]+/

const regex = /[^\[\]]+/;
const str = `[11/Sep/2016:21:58:55 +0000]`;
let m;

if ((m = regex.exec(str)) !== null) {
    // The result can be accessed through the `m`-variable.
    m.forEach((match, groupIndex) => {
        console.log(`Found match, group ${groupIndex}: ${match}`);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download