Regex expression to extract numbers from “12234 x 344 x 3545”
Need a regex expression to extract first, second and third set of numbers from below examples
- 522×318×495mm K
- 365×320×320mm A
- 465×235×145
- 480×250×465mm
- 420×235×145mm
regex
add a comment |
Need a regex expression to extract first, second and third set of numbers from below examples
- 522×318×495mm K
- 365×320×320mm A
- 465×235×145
- 480×250×465mm
- 420×235×145mm
regex
add a comment |
Need a regex expression to extract first, second and third set of numbers from below examples
- 522×318×495mm K
- 365×320×320mm A
- 465×235×145
- 480×250×465mm
- 420×235×145mm
regex
Need a regex expression to extract first, second and third set of numbers from below examples
- 522×318×495mm K
- 365×320×320mm A
- 465×235×145
- 480×250×465mm
- 420×235×145mm
regex
regex
asked Feb 7 at 11:01
TeeTee
31
31
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
This should do what you ask for:
/(d+)×(d+)×(d+)/
You can play with the pattern and get nice explanation what is captured here.
The numbers will be in the capturing group, depending on which tools you use, there will be different way of getting to the results. For example in Perl:
perl -n -e '/^(d+)×(d+)×(d+)/ && print "$1 $2 $3"'
Instead of "x" can it be any non-numeral character?
– Tee
Feb 8 at 13:09
(d+)[^0-9](d+)[^1-9](d+) Now need to remove spaces
– Tee
Feb 8 at 13:43
Exactly and if you want to accept one or more of such characters, you can do:(d+)[^0-9]+(d+)[^1-9]+(d+)
- this would also match "123xxx234xx567".
– Miroslav
Feb 8 at 16:07
how do you match 1234 xx 2333 xx x 4444 So first we need to trim all spaces
– Tee
Feb 8 at 17:07
The expression(d+)[^0-9]+(d+)[^1-9]+(d+)
that I posted in the previous comment also matches spaces, so it works as it is. The key is[^0-9]+
which essentially means "anything but number, one or more characters" so this also includes spaces and such.
– Miroslav
Feb 8 at 17:13
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1403077%2fregex-expression-to-extract-numbers-from-12234-x-344-x-3545%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This should do what you ask for:
/(d+)×(d+)×(d+)/
You can play with the pattern and get nice explanation what is captured here.
The numbers will be in the capturing group, depending on which tools you use, there will be different way of getting to the results. For example in Perl:
perl -n -e '/^(d+)×(d+)×(d+)/ && print "$1 $2 $3"'
Instead of "x" can it be any non-numeral character?
– Tee
Feb 8 at 13:09
(d+)[^0-9](d+)[^1-9](d+) Now need to remove spaces
– Tee
Feb 8 at 13:43
Exactly and if you want to accept one or more of such characters, you can do:(d+)[^0-9]+(d+)[^1-9]+(d+)
- this would also match "123xxx234xx567".
– Miroslav
Feb 8 at 16:07
how do you match 1234 xx 2333 xx x 4444 So first we need to trim all spaces
– Tee
Feb 8 at 17:07
The expression(d+)[^0-9]+(d+)[^1-9]+(d+)
that I posted in the previous comment also matches spaces, so it works as it is. The key is[^0-9]+
which essentially means "anything but number, one or more characters" so this also includes spaces and such.
– Miroslav
Feb 8 at 17:13
add a comment |
This should do what you ask for:
/(d+)×(d+)×(d+)/
You can play with the pattern and get nice explanation what is captured here.
The numbers will be in the capturing group, depending on which tools you use, there will be different way of getting to the results. For example in Perl:
perl -n -e '/^(d+)×(d+)×(d+)/ && print "$1 $2 $3"'
Instead of "x" can it be any non-numeral character?
– Tee
Feb 8 at 13:09
(d+)[^0-9](d+)[^1-9](d+) Now need to remove spaces
– Tee
Feb 8 at 13:43
Exactly and if you want to accept one or more of such characters, you can do:(d+)[^0-9]+(d+)[^1-9]+(d+)
- this would also match "123xxx234xx567".
– Miroslav
Feb 8 at 16:07
how do you match 1234 xx 2333 xx x 4444 So first we need to trim all spaces
– Tee
Feb 8 at 17:07
The expression(d+)[^0-9]+(d+)[^1-9]+(d+)
that I posted in the previous comment also matches spaces, so it works as it is. The key is[^0-9]+
which essentially means "anything but number, one or more characters" so this also includes spaces and such.
– Miroslav
Feb 8 at 17:13
add a comment |
This should do what you ask for:
/(d+)×(d+)×(d+)/
You can play with the pattern and get nice explanation what is captured here.
The numbers will be in the capturing group, depending on which tools you use, there will be different way of getting to the results. For example in Perl:
perl -n -e '/^(d+)×(d+)×(d+)/ && print "$1 $2 $3"'
This should do what you ask for:
/(d+)×(d+)×(d+)/
You can play with the pattern and get nice explanation what is captured here.
The numbers will be in the capturing group, depending on which tools you use, there will be different way of getting to the results. For example in Perl:
perl -n -e '/^(d+)×(d+)×(d+)/ && print "$1 $2 $3"'
answered Feb 7 at 11:14
MiroslavMiroslav
1461
1461
Instead of "x" can it be any non-numeral character?
– Tee
Feb 8 at 13:09
(d+)[^0-9](d+)[^1-9](d+) Now need to remove spaces
– Tee
Feb 8 at 13:43
Exactly and if you want to accept one or more of such characters, you can do:(d+)[^0-9]+(d+)[^1-9]+(d+)
- this would also match "123xxx234xx567".
– Miroslav
Feb 8 at 16:07
how do you match 1234 xx 2333 xx x 4444 So first we need to trim all spaces
– Tee
Feb 8 at 17:07
The expression(d+)[^0-9]+(d+)[^1-9]+(d+)
that I posted in the previous comment also matches spaces, so it works as it is. The key is[^0-9]+
which essentially means "anything but number, one or more characters" so this also includes spaces and such.
– Miroslav
Feb 8 at 17:13
add a comment |
Instead of "x" can it be any non-numeral character?
– Tee
Feb 8 at 13:09
(d+)[^0-9](d+)[^1-9](d+) Now need to remove spaces
– Tee
Feb 8 at 13:43
Exactly and if you want to accept one or more of such characters, you can do:(d+)[^0-9]+(d+)[^1-9]+(d+)
- this would also match "123xxx234xx567".
– Miroslav
Feb 8 at 16:07
how do you match 1234 xx 2333 xx x 4444 So first we need to trim all spaces
– Tee
Feb 8 at 17:07
The expression(d+)[^0-9]+(d+)[^1-9]+(d+)
that I posted in the previous comment also matches spaces, so it works as it is. The key is[^0-9]+
which essentially means "anything but number, one or more characters" so this also includes spaces and such.
– Miroslav
Feb 8 at 17:13
Instead of "x" can it be any non-numeral character?
– Tee
Feb 8 at 13:09
Instead of "x" can it be any non-numeral character?
– Tee
Feb 8 at 13:09
(d+)[^0-9](d+)[^1-9](d+) Now need to remove spaces
– Tee
Feb 8 at 13:43
(d+)[^0-9](d+)[^1-9](d+) Now need to remove spaces
– Tee
Feb 8 at 13:43
Exactly and if you want to accept one or more of such characters, you can do:
(d+)[^0-9]+(d+)[^1-9]+(d+)
- this would also match "123xxx234xx567".– Miroslav
Feb 8 at 16:07
Exactly and if you want to accept one or more of such characters, you can do:
(d+)[^0-9]+(d+)[^1-9]+(d+)
- this would also match "123xxx234xx567".– Miroslav
Feb 8 at 16:07
how do you match 1234 xx 2333 xx x 4444 So first we need to trim all spaces
– Tee
Feb 8 at 17:07
how do you match 1234 xx 2333 xx x 4444 So first we need to trim all spaces
– Tee
Feb 8 at 17:07
The expression
(d+)[^0-9]+(d+)[^1-9]+(d+)
that I posted in the previous comment also matches spaces, so it works as it is. The key is [^0-9]+
which essentially means "anything but number, one or more characters" so this also includes spaces and such.– Miroslav
Feb 8 at 17:13
The expression
(d+)[^0-9]+(d+)[^1-9]+(d+)
that I posted in the previous comment also matches spaces, so it works as it is. The key is [^0-9]+
which essentially means "anything but number, one or more characters" so this also includes spaces and such.– Miroslav
Feb 8 at 17:13
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1403077%2fregex-expression-to-extract-numbers-from-12234-x-344-x-3545%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown