How to remove every character after number of digits [duplicate]
This question already has an answer here:
How can I cut a string after X characters?
4 answers
How to remove every character after 9 digits.
I tried the following but is removing the whole word
$(this).val(str.replace(/^.{9,}$/g,""));
javascript regex
marked as duplicate by 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 14 '18 at 12:09
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:
How can I cut a string after X characters?
4 answers
How to remove every character after 9 digits.
I tried the following but is removing the whole word
$(this).val(str.replace(/^.{9,}$/g,""));
javascript regex
marked as duplicate by 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 14 '18 at 12:09
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.
1
Your regex does not match only digits, it matches a line of 9 or more non-linebreak chars. What do you mean to do? Please clarify with an example.
– Wiktor Stribiżew
Nov 14 '18 at 11:48
add a comment |
This question already has an answer here:
How can I cut a string after X characters?
4 answers
How to remove every character after 9 digits.
I tried the following but is removing the whole word
$(this).val(str.replace(/^.{9,}$/g,""));
javascript regex
This question already has an answer here:
How can I cut a string after X characters?
4 answers
How to remove every character after 9 digits.
I tried the following but is removing the whole word
$(this).val(str.replace(/^.{9,}$/g,""));
This question already has an answer here:
How can I cut a string after X characters?
4 answers
javascript regex
javascript regex
edited Nov 14 '18 at 11:48
Flimzy
38.4k96597
38.4k96597
asked Nov 14 '18 at 11:47
Khaled RamadanKhaled Ramadan
3318
3318
marked as duplicate by 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 14 '18 at 12:09
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 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 14 '18 at 12:09
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.
1
Your regex does not match only digits, it matches a line of 9 or more non-linebreak chars. What do you mean to do? Please clarify with an example.
– Wiktor Stribiżew
Nov 14 '18 at 11:48
add a comment |
1
Your regex does not match only digits, it matches a line of 9 or more non-linebreak chars. What do you mean to do? Please clarify with an example.
– Wiktor Stribiżew
Nov 14 '18 at 11:48
1
1
Your regex does not match only digits, it matches a line of 9 or more non-linebreak chars. What do you mean to do? Please clarify with an example.
– Wiktor Stribiżew
Nov 14 '18 at 11:48
Your regex does not match only digits, it matches a line of 9 or more non-linebreak chars. What do you mean to do? Please clarify with an example.
– Wiktor Stribiżew
Nov 14 '18 at 11:48
add a comment |
1 Answer
1
active
oldest
votes
You don't need regex to do this. You can use .substr()
Here I used str.substr(0, 9);
where 0
is the start of the string you want to keep, and 9
is the length of the portion you want to keep (ie: to the 0+9
th index is where it will cut off the string):
let str = "123456789Hello world!";
let res = str.substr(0, 9);
console.log(res);
Thank you for you answersubstring
solve my issue
– Khaled Ramadan
Nov 14 '18 at 11:57
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You don't need regex to do this. You can use .substr()
Here I used str.substr(0, 9);
where 0
is the start of the string you want to keep, and 9
is the length of the portion you want to keep (ie: to the 0+9
th index is where it will cut off the string):
let str = "123456789Hello world!";
let res = str.substr(0, 9);
console.log(res);
Thank you for you answersubstring
solve my issue
– Khaled Ramadan
Nov 14 '18 at 11:57
add a comment |
You don't need regex to do this. You can use .substr()
Here I used str.substr(0, 9);
where 0
is the start of the string you want to keep, and 9
is the length of the portion you want to keep (ie: to the 0+9
th index is where it will cut off the string):
let str = "123456789Hello world!";
let res = str.substr(0, 9);
console.log(res);
Thank you for you answersubstring
solve my issue
– Khaled Ramadan
Nov 14 '18 at 11:57
add a comment |
You don't need regex to do this. You can use .substr()
Here I used str.substr(0, 9);
where 0
is the start of the string you want to keep, and 9
is the length of the portion you want to keep (ie: to the 0+9
th index is where it will cut off the string):
let str = "123456789Hello world!";
let res = str.substr(0, 9);
console.log(res);
You don't need regex to do this. You can use .substr()
Here I used str.substr(0, 9);
where 0
is the start of the string you want to keep, and 9
is the length of the portion you want to keep (ie: to the 0+9
th index is where it will cut off the string):
let str = "123456789Hello world!";
let res = str.substr(0, 9);
console.log(res);
let str = "123456789Hello world!";
let res = str.substr(0, 9);
console.log(res);
let str = "123456789Hello world!";
let res = str.substr(0, 9);
console.log(res);
edited Nov 14 '18 at 12:15
answered Nov 14 '18 at 11:51
Nick ParsonsNick Parsons
7,0752724
7,0752724
Thank you for you answersubstring
solve my issue
– Khaled Ramadan
Nov 14 '18 at 11:57
add a comment |
Thank you for you answersubstring
solve my issue
– Khaled Ramadan
Nov 14 '18 at 11:57
Thank you for you answer
substring
solve my issue– Khaled Ramadan
Nov 14 '18 at 11:57
Thank you for you answer
substring
solve my issue– Khaled Ramadan
Nov 14 '18 at 11:57
add a comment |
1
Your regex does not match only digits, it matches a line of 9 or more non-linebreak chars. What do you mean to do? Please clarify with an example.
– Wiktor Stribiżew
Nov 14 '18 at 11:48