regex match number in parentheses (Firefox) [duplicate]
This question already has an answer here:
Javascript regex negative lookbehind not working in firefox
3 answers
I have string like this:
(3) Request Inbox
Now I want to detect number 3
in parentheses. Pay attention just 3
. I write this regex in javascript but it doesn't work in Firefox.
var regex = new RegExp(/(?<=()d+(?:.d+)?(?=))/g);
Error in console: SyntaxError: invalid regexp group
Demo link
javascript regex string
marked as duplicate by Mohammad, Wiktor Stribiżew
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 15 '18 at 7:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Javascript regex negative lookbehind not working in firefox
3 answers
I have string like this:
(3) Request Inbox
Now I want to detect number 3
in parentheses. Pay attention just 3
. I write this regex in javascript but it doesn't work in Firefox.
var regex = new RegExp(/(?<=()d+(?:.d+)?(?=))/g);
Error in console: SyntaxError: invalid regexp group
Demo link
javascript regex string
marked as duplicate by Mohammad, Wiktor Stribiżew
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 15 '18 at 7:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
If you just want to match the number, do you even need the lookahead? What about something as simple as:/^((d+))/g
- it matches in group 1. Or do you mean, only the full match?
– fubar
Nov 15 '18 at 6:22
add a comment |
This question already has an answer here:
Javascript regex negative lookbehind not working in firefox
3 answers
I have string like this:
(3) Request Inbox
Now I want to detect number 3
in parentheses. Pay attention just 3
. I write this regex in javascript but it doesn't work in Firefox.
var regex = new RegExp(/(?<=()d+(?:.d+)?(?=))/g);
Error in console: SyntaxError: invalid regexp group
Demo link
javascript regex string
This question already has an answer here:
Javascript regex negative lookbehind not working in firefox
3 answers
I have string like this:
(3) Request Inbox
Now I want to detect number 3
in parentheses. Pay attention just 3
. I write this regex in javascript but it doesn't work in Firefox.
var regex = new RegExp(/(?<=()d+(?:.d+)?(?=))/g);
Error in console: SyntaxError: invalid regexp group
Demo link
This question already has an answer here:
Javascript regex negative lookbehind not working in firefox
3 answers
javascript regex string
javascript regex string
edited Nov 15 '18 at 6:10
Ehsan Ali
asked Nov 15 '18 at 5:54
Ehsan AliEhsan Ali
48011032
48011032
marked as duplicate by Mohammad, Wiktor Stribiżew
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 15 '18 at 7:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Mohammad, Wiktor Stribiżew
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 15 '18 at 7:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
If you just want to match the number, do you even need the lookahead? What about something as simple as:/^((d+))/g
- it matches in group 1. Or do you mean, only the full match?
– fubar
Nov 15 '18 at 6:22
add a comment |
If you just want to match the number, do you even need the lookahead? What about something as simple as:/^((d+))/g
- it matches in group 1. Or do you mean, only the full match?
– fubar
Nov 15 '18 at 6:22
If you just want to match the number, do you even need the lookahead? What about something as simple as:
/^((d+))/g
- it matches in group 1. Or do you mean, only the full match?– fubar
Nov 15 '18 at 6:22
If you just want to match the number, do you even need the lookahead? What about something as simple as:
/^((d+))/g
- it matches in group 1. Or do you mean, only the full match?– fubar
Nov 15 '18 at 6:22
add a comment |
2 Answers
2
active
oldest
votes
For a full match try this:
var regex = new RegExp(/(?=d+))d+/g);
Welcome to StackOverflow! Your answer need more explanation about how the code works to be a good answer.
– Foo
Nov 15 '18 at 6:30
add a comment |
Positive lookbehind is not supported by most browsers so use an alternative way to get your answer.
Something like this,
var string = "somestring(12)";
var exp = /(?:()(d+)(?:.d+)?(?=))/;
var mat = string.match(exp);
if(mat)
console.log(mat[1]);// second index
This should only give 12 as the answer
it has problem, please check it https://regex101.com/r/eNOcvx/2
– Ehsan Ali
Nov 15 '18 at 8:12
1
The first parenthesis is shown as 'matched' string but when you get the matched group it will come out as number only
– Simba3696
Nov 15 '18 at 8:19
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
For a full match try this:
var regex = new RegExp(/(?=d+))d+/g);
Welcome to StackOverflow! Your answer need more explanation about how the code works to be a good answer.
– Foo
Nov 15 '18 at 6:30
add a comment |
For a full match try this:
var regex = new RegExp(/(?=d+))d+/g);
Welcome to StackOverflow! Your answer need more explanation about how the code works to be a good answer.
– Foo
Nov 15 '18 at 6:30
add a comment |
For a full match try this:
var regex = new RegExp(/(?=d+))d+/g);
For a full match try this:
var regex = new RegExp(/(?=d+))d+/g);
answered Nov 15 '18 at 6:27
Andrey StarkovAndrey Starkov
894
894
Welcome to StackOverflow! Your answer need more explanation about how the code works to be a good answer.
– Foo
Nov 15 '18 at 6:30
add a comment |
Welcome to StackOverflow! Your answer need more explanation about how the code works to be a good answer.
– Foo
Nov 15 '18 at 6:30
Welcome to StackOverflow! Your answer need more explanation about how the code works to be a good answer.
– Foo
Nov 15 '18 at 6:30
Welcome to StackOverflow! Your answer need more explanation about how the code works to be a good answer.
– Foo
Nov 15 '18 at 6:30
add a comment |
Positive lookbehind is not supported by most browsers so use an alternative way to get your answer.
Something like this,
var string = "somestring(12)";
var exp = /(?:()(d+)(?:.d+)?(?=))/;
var mat = string.match(exp);
if(mat)
console.log(mat[1]);// second index
This should only give 12 as the answer
it has problem, please check it https://regex101.com/r/eNOcvx/2
– Ehsan Ali
Nov 15 '18 at 8:12
1
The first parenthesis is shown as 'matched' string but when you get the matched group it will come out as number only
– Simba3696
Nov 15 '18 at 8:19
add a comment |
Positive lookbehind is not supported by most browsers so use an alternative way to get your answer.
Something like this,
var string = "somestring(12)";
var exp = /(?:()(d+)(?:.d+)?(?=))/;
var mat = string.match(exp);
if(mat)
console.log(mat[1]);// second index
This should only give 12 as the answer
it has problem, please check it https://regex101.com/r/eNOcvx/2
– Ehsan Ali
Nov 15 '18 at 8:12
1
The first parenthesis is shown as 'matched' string but when you get the matched group it will come out as number only
– Simba3696
Nov 15 '18 at 8:19
add a comment |
Positive lookbehind is not supported by most browsers so use an alternative way to get your answer.
Something like this,
var string = "somestring(12)";
var exp = /(?:()(d+)(?:.d+)?(?=))/;
var mat = string.match(exp);
if(mat)
console.log(mat[1]);// second index
This should only give 12 as the answer
Positive lookbehind is not supported by most browsers so use an alternative way to get your answer.
Something like this,
var string = "somestring(12)";
var exp = /(?:()(d+)(?:.d+)?(?=))/;
var mat = string.match(exp);
if(mat)
console.log(mat[1]);// second index
This should only give 12 as the answer
edited Nov 15 '18 at 8:33
Ehsan Ali
48011032
48011032
answered Nov 15 '18 at 6:40
Simba3696Simba3696
267
267
it has problem, please check it https://regex101.com/r/eNOcvx/2
– Ehsan Ali
Nov 15 '18 at 8:12
1
The first parenthesis is shown as 'matched' string but when you get the matched group it will come out as number only
– Simba3696
Nov 15 '18 at 8:19
add a comment |
it has problem, please check it https://regex101.com/r/eNOcvx/2
– Ehsan Ali
Nov 15 '18 at 8:12
1
The first parenthesis is shown as 'matched' string but when you get the matched group it will come out as number only
– Simba3696
Nov 15 '18 at 8:19
it has problem, please check it https://regex101.com/r/eNOcvx/2
– Ehsan Ali
Nov 15 '18 at 8:12
it has problem, please check it https://regex101.com/r/eNOcvx/2
– Ehsan Ali
Nov 15 '18 at 8:12
1
1
The first parenthesis is shown as 'matched' string but when you get the matched group it will come out as number only
– Simba3696
Nov 15 '18 at 8:19
The first parenthesis is shown as 'matched' string but when you get the matched group it will come out as number only
– Simba3696
Nov 15 '18 at 8:19
add a comment |
If you just want to match the number, do you even need the lookahead? What about something as simple as:
/^((d+))/g
- it matches in group 1. Or do you mean, only the full match?– fubar
Nov 15 '18 at 6:22