Variable in regex in MongoDB [duplicate]
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
This question already has an answer here:
Converting user input string to regular expression
10 answers
how to pass a variable to a regex
4 answers
This works fine:
db.collecton.find({code: {
$regex: /babcb/,
$options: 'i'
}})
But how to do this with variable code = 'abc'? I tried to do like this, but it finds nothing:
db.collection.find({code: {
$regex: 'b' + code + 'b',
$options: 'i'
}})
(I need to find documents with field code equal the variable, but with /i option, so I can't write just code: code. With $regex: code it also returns documents with code like qabcg)
mongodb
marked as duplicate by Neil Lunn
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 22 '18 at 7:49
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:
Converting user input string to regular expression
10 answers
how to pass a variable to a regex
4 answers
This works fine:
db.collecton.find({code: {
$regex: /babcb/,
$options: 'i'
}})
But how to do this with variable code = 'abc'? I tried to do like this, but it finds nothing:
db.collection.find({code: {
$regex: 'b' + code + 'b',
$options: 'i'
}})
(I need to find documents with field code equal the variable, but with /i option, so I can't write just code: code. With $regex: code it also returns documents with code like qabcg)
mongodb
marked as duplicate by Neil Lunn
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 22 '18 at 7:49
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:
Converting user input string to regular expression
10 answers
how to pass a variable to a regex
4 answers
This works fine:
db.collecton.find({code: {
$regex: /babcb/,
$options: 'i'
}})
But how to do this with variable code = 'abc'? I tried to do like this, but it finds nothing:
db.collection.find({code: {
$regex: 'b' + code + 'b',
$options: 'i'
}})
(I need to find documents with field code equal the variable, but with /i option, so I can't write just code: code. With $regex: code it also returns documents with code like qabcg)
mongodb
This question already has an answer here:
Converting user input string to regular expression
10 answers
how to pass a variable to a regex
4 answers
This works fine:
db.collecton.find({code: {
$regex: /babcb/,
$options: 'i'
}})
But how to do this with variable code = 'abc'? I tried to do like this, but it finds nothing:
db.collection.find({code: {
$regex: 'b' + code + 'b',
$options: 'i'
}})
(I need to find documents with field code equal the variable, but with /i option, so I can't write just code: code. With $regex: code it also returns documents with code like qabcg)
This question already has an answer here:
Converting user input string to regular expression
10 answers
how to pass a variable to a regex
4 answers
mongodb
mongodb
asked Nov 22 '18 at 7:44
golubluegolublue
11
11
marked as duplicate by Neil Lunn
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 22 '18 at 7:49
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 Neil Lunn
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 22 '18 at 7:49
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 |
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes