Using RegExp to filter receipt for prices
up vote
1
down vote
favorite
With my programm I want to be able to make a picture of any receipt and filter certain informations, one beeing the price.
My Input is the following:
Input:
----------
BT em <br/>
SCHWEINFURT _OSKAR-VON-MILLER-STR.6 <br/>
RADIESCHEN **0,59** <br/>
KAESEAUFSCH. **1.39** <br/>
BAUCHSPECK **1,19** <br/>
BAUCHSPECK **1,19** <br/>
DORNFELDER **0,99**<br/>
CLEMENTINEN **2,49**<br/>
L&M BLUE **3,50**<br/>
L&M BLUE **3,50**<br/>
SUMME EUR **14,84** *<br/>
BAR **50,00**<br/>
RUCKGELD EUR **35,16**<br/>
“ENTHALTENE MEHRWERTSTEUER A<br/>
MWST NETTO<br/>
**7,00** % **0,45** **6,40**<br/>
**19,00** % **1,28** **6,71**<br/>
SUMME MWST **1,73** **13,11**<br/>
EDEKA HANDELSGFSELLSCHAFT<br/>
NORDBAYERN-SACHSEN-THURINGEN MBH<br/>
STEUERNUMMER: 257/115/30471<br/>
QUITTUNG<br/>
NUTZEN SIE DIF EDECARD<br/>
PUNKTE_SAMMELN+PRAMIEN ERWERBEN<br/>
THR EINKAUF WARE UNS<br/>
1 BONUSPUNKTE WERT GEWESEN !<br/>
08.12.07 16:27 37589 48 4 8500<br/>
FS BEDIENTE STE: H. SEUFERT :<br/>
VIELEN DANK FÜR IHREN EINKAUF!<br/>
AUF WIEDERSEHEN IM E-CENTER<br/>
UNSERE ÖFFNUNGSZEITEN FÜR SIE:<br/>
MONTAG-SAMSTAG: 0800-20 . 00UER<br/>
The informations I want to obtain are bold.
Tried RegExp:
First I tried the following RegExp:
/(([d]1,2)(,|.)[d]2)/g
I choose this one, because
I am looking for more than one match, therefore /
(...) /g
- My prices got one or two digits in the beginning, therefore
[d]1,2 - After the first to digits, there is either a dot or a comma, therefore
(,|.) - In the end, there are two digits, therefore
[d]2
- My prices got one or two digits in the beginning, therefore

As you can see part of the date is a match, which I don't want.
Right now I don't mind the part after MWST Netto to match.
My approach to the problem
My idea was to look for the dot. So I tried adding
[^.] before and after my RegExp

As you can see my problem is still there. I don't understand why 6,40 and 6,71 is not a match anymore as there is no dot before or after.
Does anyone got an idea what to try next? I was thinking about and AND-Statement, so I would use my first RegExp and then exclude anything that looks like a date.
But I'm not sure how to that.
I would really appreciate any tipps or ideas you have. If there is anything unclear or you need more information, please do not hesitate to ask.
javascript regex
add a comment |
up vote
1
down vote
favorite
With my programm I want to be able to make a picture of any receipt and filter certain informations, one beeing the price.
My Input is the following:
Input:
----------
BT em <br/>
SCHWEINFURT _OSKAR-VON-MILLER-STR.6 <br/>
RADIESCHEN **0,59** <br/>
KAESEAUFSCH. **1.39** <br/>
BAUCHSPECK **1,19** <br/>
BAUCHSPECK **1,19** <br/>
DORNFELDER **0,99**<br/>
CLEMENTINEN **2,49**<br/>
L&M BLUE **3,50**<br/>
L&M BLUE **3,50**<br/>
SUMME EUR **14,84** *<br/>
BAR **50,00**<br/>
RUCKGELD EUR **35,16**<br/>
“ENTHALTENE MEHRWERTSTEUER A<br/>
MWST NETTO<br/>
**7,00** % **0,45** **6,40**<br/>
**19,00** % **1,28** **6,71**<br/>
SUMME MWST **1,73** **13,11**<br/>
EDEKA HANDELSGFSELLSCHAFT<br/>
NORDBAYERN-SACHSEN-THURINGEN MBH<br/>
STEUERNUMMER: 257/115/30471<br/>
QUITTUNG<br/>
NUTZEN SIE DIF EDECARD<br/>
PUNKTE_SAMMELN+PRAMIEN ERWERBEN<br/>
THR EINKAUF WARE UNS<br/>
1 BONUSPUNKTE WERT GEWESEN !<br/>
08.12.07 16:27 37589 48 4 8500<br/>
FS BEDIENTE STE: H. SEUFERT :<br/>
VIELEN DANK FÜR IHREN EINKAUF!<br/>
AUF WIEDERSEHEN IM E-CENTER<br/>
UNSERE ÖFFNUNGSZEITEN FÜR SIE:<br/>
MONTAG-SAMSTAG: 0800-20 . 00UER<br/>
The informations I want to obtain are bold.
Tried RegExp:
First I tried the following RegExp:
/(([d]1,2)(,|.)[d]2)/g
I choose this one, because
I am looking for more than one match, therefore /
(...) /g
- My prices got one or two digits in the beginning, therefore
[d]1,2 - After the first to digits, there is either a dot or a comma, therefore
(,|.) - In the end, there are two digits, therefore
[d]2
- My prices got one or two digits in the beginning, therefore

As you can see part of the date is a match, which I don't want.
Right now I don't mind the part after MWST Netto to match.
My approach to the problem
My idea was to look for the dot. So I tried adding
[^.] before and after my RegExp

As you can see my problem is still there. I don't understand why 6,40 and 6,71 is not a match anymore as there is no dot before or after.
Does anyone got an idea what to try next? I was thinking about and AND-Statement, so I would use my first RegExp and then exclude anything that looks like a date.
But I'm not sure how to that.
I would really appreciate any tipps or ideas you have. If there is anything unclear or you need more information, please do not hesitate to ask.
javascript regex
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
With my programm I want to be able to make a picture of any receipt and filter certain informations, one beeing the price.
My Input is the following:
Input:
----------
BT em <br/>
SCHWEINFURT _OSKAR-VON-MILLER-STR.6 <br/>
RADIESCHEN **0,59** <br/>
KAESEAUFSCH. **1.39** <br/>
BAUCHSPECK **1,19** <br/>
BAUCHSPECK **1,19** <br/>
DORNFELDER **0,99**<br/>
CLEMENTINEN **2,49**<br/>
L&M BLUE **3,50**<br/>
L&M BLUE **3,50**<br/>
SUMME EUR **14,84** *<br/>
BAR **50,00**<br/>
RUCKGELD EUR **35,16**<br/>
“ENTHALTENE MEHRWERTSTEUER A<br/>
MWST NETTO<br/>
**7,00** % **0,45** **6,40**<br/>
**19,00** % **1,28** **6,71**<br/>
SUMME MWST **1,73** **13,11**<br/>
EDEKA HANDELSGFSELLSCHAFT<br/>
NORDBAYERN-SACHSEN-THURINGEN MBH<br/>
STEUERNUMMER: 257/115/30471<br/>
QUITTUNG<br/>
NUTZEN SIE DIF EDECARD<br/>
PUNKTE_SAMMELN+PRAMIEN ERWERBEN<br/>
THR EINKAUF WARE UNS<br/>
1 BONUSPUNKTE WERT GEWESEN !<br/>
08.12.07 16:27 37589 48 4 8500<br/>
FS BEDIENTE STE: H. SEUFERT :<br/>
VIELEN DANK FÜR IHREN EINKAUF!<br/>
AUF WIEDERSEHEN IM E-CENTER<br/>
UNSERE ÖFFNUNGSZEITEN FÜR SIE:<br/>
MONTAG-SAMSTAG: 0800-20 . 00UER<br/>
The informations I want to obtain are bold.
Tried RegExp:
First I tried the following RegExp:
/(([d]1,2)(,|.)[d]2)/g
I choose this one, because
I am looking for more than one match, therefore /
(...) /g
- My prices got one or two digits in the beginning, therefore
[d]1,2 - After the first to digits, there is either a dot or a comma, therefore
(,|.) - In the end, there are two digits, therefore
[d]2
- My prices got one or two digits in the beginning, therefore

As you can see part of the date is a match, which I don't want.
Right now I don't mind the part after MWST Netto to match.
My approach to the problem
My idea was to look for the dot. So I tried adding
[^.] before and after my RegExp

As you can see my problem is still there. I don't understand why 6,40 and 6,71 is not a match anymore as there is no dot before or after.
Does anyone got an idea what to try next? I was thinking about and AND-Statement, so I would use my first RegExp and then exclude anything that looks like a date.
But I'm not sure how to that.
I would really appreciate any tipps or ideas you have. If there is anything unclear or you need more information, please do not hesitate to ask.
javascript regex
With my programm I want to be able to make a picture of any receipt and filter certain informations, one beeing the price.
My Input is the following:
Input:
----------
BT em <br/>
SCHWEINFURT _OSKAR-VON-MILLER-STR.6 <br/>
RADIESCHEN **0,59** <br/>
KAESEAUFSCH. **1.39** <br/>
BAUCHSPECK **1,19** <br/>
BAUCHSPECK **1,19** <br/>
DORNFELDER **0,99**<br/>
CLEMENTINEN **2,49**<br/>
L&M BLUE **3,50**<br/>
L&M BLUE **3,50**<br/>
SUMME EUR **14,84** *<br/>
BAR **50,00**<br/>
RUCKGELD EUR **35,16**<br/>
“ENTHALTENE MEHRWERTSTEUER A<br/>
MWST NETTO<br/>
**7,00** % **0,45** **6,40**<br/>
**19,00** % **1,28** **6,71**<br/>
SUMME MWST **1,73** **13,11**<br/>
EDEKA HANDELSGFSELLSCHAFT<br/>
NORDBAYERN-SACHSEN-THURINGEN MBH<br/>
STEUERNUMMER: 257/115/30471<br/>
QUITTUNG<br/>
NUTZEN SIE DIF EDECARD<br/>
PUNKTE_SAMMELN+PRAMIEN ERWERBEN<br/>
THR EINKAUF WARE UNS<br/>
1 BONUSPUNKTE WERT GEWESEN !<br/>
08.12.07 16:27 37589 48 4 8500<br/>
FS BEDIENTE STE: H. SEUFERT :<br/>
VIELEN DANK FÜR IHREN EINKAUF!<br/>
AUF WIEDERSEHEN IM E-CENTER<br/>
UNSERE ÖFFNUNGSZEITEN FÜR SIE:<br/>
MONTAG-SAMSTAG: 0800-20 . 00UER<br/>
The informations I want to obtain are bold.
Tried RegExp:
First I tried the following RegExp:
/(([d]1,2)(,|.)[d]2)/g
I choose this one, because
I am looking for more than one match, therefore /
(...) /g
- My prices got one or two digits in the beginning, therefore
[d]1,2 - After the first to digits, there is either a dot or a comma, therefore
(,|.) - In the end, there are two digits, therefore
[d]2
- My prices got one or two digits in the beginning, therefore

As you can see part of the date is a match, which I don't want.
Right now I don't mind the part after MWST Netto to match.
My approach to the problem
My idea was to look for the dot. So I tried adding
[^.] before and after my RegExp

As you can see my problem is still there. I don't understand why 6,40 and 6,71 is not a match anymore as there is no dot before or after.
Does anyone got an idea what to try next? I was thinking about and AND-Statement, so I would use my first RegExp and then exclude anything that looks like a date.
But I'm not sure how to that.
I would really appreciate any tipps or ideas you have. If there is anything unclear or you need more information, please do not hesitate to ask.
javascript regex
javascript regex
edited Nov 11 at 21:57
Wiktor Stribiżew
306k16125202
306k16125202
asked Nov 9 at 9:21
Th0rne
83
83
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
You may use
/(?:^|[^.d])(d1,2[,.]d2)(?![.d])/g
and grab the contents of Group 1. See the regex demo.
Details
(?:^|[^.d])- start of string or any char other than.and digit(d1,2[,.]d2)- Group 1: 1 or 2 digits,.or,, two digits(?![.d])- no.or digit immediately to the right is allowed.
JS demo:
var text = "BT em rnSCHWEINFURT _OSKAR-VON-MILLER-STR.6 rnRADIESCHEN 0,59 rnKAESEAUFSCH. 1.39 rnBAUCHSPECK 1,19 rnBAUCHSPECK 1,19 rnDORNFELDER 0,99rnCLEMENTINEN 2,49rnL&M BLUE 3,50rnL&M BLUE 3,50rnSUMME EUR 14,84 *rnBAR 50,00rnrnRUCKGELD EUR 35,16rn“ENTHALTENE MEHRWERTSTEUER ArnMWST NETTOrn7,00 % 0,45 6,40rn19,00 % 1,28 6,71rnSUMME MWST 1,73 13,11rnEDEKA HANDELSGFSELLSCHAFTrnNORDBAYERN-SACHSEN-THURINGEN MBHrnSTEUERNUMMER: 257/115/30471rnQUITTUNGrnNUTZEN SIE DIF EDECARDrnPUNKTE_SAMMELN+PRAMIEN ERWERBENrnTHR EINKAUF WARE UNSrn1 BONUSPUNKTE WERT GEWESEN !rn08.12.07 16:27 37589 48 4 8500rnFS BEDIENTE STE: H. SEUFERT :rnVIELEN DANK FÜR IHREN EINKAUF!rnAUF WIEDERSEHEN IM E-CENTERrnUNSERE ÖFFNUNGSZEITEN FÜR SIE:rnMONTAG-SAMSTAG: 0800-20 . 00UER";
var rx = /(?:^|[^.d])(d1,2[,.]d2)(?![.d])/g;
var m, res = ;
while (m = rx.exec(text))
res.push(m[1]);
console.log(res);
1
Thank you so much for your response, it worked :)
– Th0rne
Nov 9 at 9:52
@Th0rne Note that the other posted solution is not generic and you might need to adjust it later to exclude more and more contexts while my solution handles next to all edge cases. If you do not want to match numbers glued to words, just add word boundaries,/(?:^|[^.d])b(d1,2[,.]d2)b(?![.d])/g
– Wiktor Stribiżew
Nov 9 at 9:59
add a comment |
up vote
1
down vote
One way could be to use an alternation to match the format that you don't want and then capture in a group what you do want:
d+.d+.d+|(d1,2[.,]d1,2)
Explanation
d+.d+.d+Match pattern that you don't want to capture (or for exampled2.d2.d2if you want to be more specific)|Or(d1,2[.,]d2)Capture in a group 1 or 2 digits, a comma or dot and then 2 digits
Regex demo
const regex = /d+.d+.d+|(d1,2[.,]d2)/g;
const str = `BT em
SCHWEINFURT _OSKAR-VON-MILLER-STR.6
RADIESCHEN 0,59
KAESEAUFSCH. 1.39
BAUCHSPECK 1,19
BAUCHSPECK 1,19
DORNFELDER 0,99
CLEMENTINEN 2,49
L&M BLUE 3,50
L&M BLUE 3,50
SUMME EUR 14,84 *
BAR 50,00
RUCKGELD EUR 35,16
“ENTHALTENE MEHRWERTSTEUER A
MWST NETTO
7,00 % 0,45 6,40
19,00 % 1,28 6,71
SUMME MWST 1,73 13,11
EDEKA HANDELSGFSELLSCHAFT
NORDBAYERN-SACHSEN-THURINGEN MBH
STEUERNUMMER: 257/115/30471
QUITTUNG
NUTZEN SIE DIF EDECARD
PUNKTE_SAMMELN+PRAMIEN ERWERBEN
THR EINKAUF WARE UNS
1 BONUSPUNKTE WERT GEWESEN !
08.12.07 16:27 37589 48 4 8500
FS BEDIENTE STE: H. SEUFERT :
VIELEN DANK FÜR IHREN EINKAUF!
AUF WIEDERSEHEN IM E-CENTER
UNSERE ÖFFNUNGSZEITEN FÜR SIE:
MONTAG-SAMSTAG: 0800-20 . 00UER`;
let m;
while ((m = regex.exec(str)) !== null)
if (m.index === regex.lastIndex)
regex.lastIndex++;
if (m[1])
console.log(m[1]);
1
Thank you so much. I wasn't really are of the different groups and that is really helpful.
– Th0rne
Nov 9 at 9:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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',
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%2fstackoverflow.com%2fquestions%2f53222893%2fusing-regexp-to-filter-receipt-for-prices%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You may use
/(?:^|[^.d])(d1,2[,.]d2)(?![.d])/g
and grab the contents of Group 1. See the regex demo.
Details
(?:^|[^.d])- start of string or any char other than.and digit(d1,2[,.]d2)- Group 1: 1 or 2 digits,.or,, two digits(?![.d])- no.or digit immediately to the right is allowed.
JS demo:
var text = "BT em rnSCHWEINFURT _OSKAR-VON-MILLER-STR.6 rnRADIESCHEN 0,59 rnKAESEAUFSCH. 1.39 rnBAUCHSPECK 1,19 rnBAUCHSPECK 1,19 rnDORNFELDER 0,99rnCLEMENTINEN 2,49rnL&M BLUE 3,50rnL&M BLUE 3,50rnSUMME EUR 14,84 *rnBAR 50,00rnrnRUCKGELD EUR 35,16rn“ENTHALTENE MEHRWERTSTEUER ArnMWST NETTOrn7,00 % 0,45 6,40rn19,00 % 1,28 6,71rnSUMME MWST 1,73 13,11rnEDEKA HANDELSGFSELLSCHAFTrnNORDBAYERN-SACHSEN-THURINGEN MBHrnSTEUERNUMMER: 257/115/30471rnQUITTUNGrnNUTZEN SIE DIF EDECARDrnPUNKTE_SAMMELN+PRAMIEN ERWERBENrnTHR EINKAUF WARE UNSrn1 BONUSPUNKTE WERT GEWESEN !rn08.12.07 16:27 37589 48 4 8500rnFS BEDIENTE STE: H. SEUFERT :rnVIELEN DANK FÜR IHREN EINKAUF!rnAUF WIEDERSEHEN IM E-CENTERrnUNSERE ÖFFNUNGSZEITEN FÜR SIE:rnMONTAG-SAMSTAG: 0800-20 . 00UER";
var rx = /(?:^|[^.d])(d1,2[,.]d2)(?![.d])/g;
var m, res = ;
while (m = rx.exec(text))
res.push(m[1]);
console.log(res);
1
Thank you so much for your response, it worked :)
– Th0rne
Nov 9 at 9:52
@Th0rne Note that the other posted solution is not generic and you might need to adjust it later to exclude more and more contexts while my solution handles next to all edge cases. If you do not want to match numbers glued to words, just add word boundaries,/(?:^|[^.d])b(d1,2[,.]d2)b(?![.d])/g
– Wiktor Stribiżew
Nov 9 at 9:59
add a comment |
up vote
1
down vote
accepted
You may use
/(?:^|[^.d])(d1,2[,.]d2)(?![.d])/g
and grab the contents of Group 1. See the regex demo.
Details
(?:^|[^.d])- start of string or any char other than.and digit(d1,2[,.]d2)- Group 1: 1 or 2 digits,.or,, two digits(?![.d])- no.or digit immediately to the right is allowed.
JS demo:
var text = "BT em rnSCHWEINFURT _OSKAR-VON-MILLER-STR.6 rnRADIESCHEN 0,59 rnKAESEAUFSCH. 1.39 rnBAUCHSPECK 1,19 rnBAUCHSPECK 1,19 rnDORNFELDER 0,99rnCLEMENTINEN 2,49rnL&M BLUE 3,50rnL&M BLUE 3,50rnSUMME EUR 14,84 *rnBAR 50,00rnrnRUCKGELD EUR 35,16rn“ENTHALTENE MEHRWERTSTEUER ArnMWST NETTOrn7,00 % 0,45 6,40rn19,00 % 1,28 6,71rnSUMME MWST 1,73 13,11rnEDEKA HANDELSGFSELLSCHAFTrnNORDBAYERN-SACHSEN-THURINGEN MBHrnSTEUERNUMMER: 257/115/30471rnQUITTUNGrnNUTZEN SIE DIF EDECARDrnPUNKTE_SAMMELN+PRAMIEN ERWERBENrnTHR EINKAUF WARE UNSrn1 BONUSPUNKTE WERT GEWESEN !rn08.12.07 16:27 37589 48 4 8500rnFS BEDIENTE STE: H. SEUFERT :rnVIELEN DANK FÜR IHREN EINKAUF!rnAUF WIEDERSEHEN IM E-CENTERrnUNSERE ÖFFNUNGSZEITEN FÜR SIE:rnMONTAG-SAMSTAG: 0800-20 . 00UER";
var rx = /(?:^|[^.d])(d1,2[,.]d2)(?![.d])/g;
var m, res = ;
while (m = rx.exec(text))
res.push(m[1]);
console.log(res);
1
Thank you so much for your response, it worked :)
– Th0rne
Nov 9 at 9:52
@Th0rne Note that the other posted solution is not generic and you might need to adjust it later to exclude more and more contexts while my solution handles next to all edge cases. If you do not want to match numbers glued to words, just add word boundaries,/(?:^|[^.d])b(d1,2[,.]d2)b(?![.d])/g
– Wiktor Stribiżew
Nov 9 at 9:59
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You may use
/(?:^|[^.d])(d1,2[,.]d2)(?![.d])/g
and grab the contents of Group 1. See the regex demo.
Details
(?:^|[^.d])- start of string or any char other than.and digit(d1,2[,.]d2)- Group 1: 1 or 2 digits,.or,, two digits(?![.d])- no.or digit immediately to the right is allowed.
JS demo:
var text = "BT em rnSCHWEINFURT _OSKAR-VON-MILLER-STR.6 rnRADIESCHEN 0,59 rnKAESEAUFSCH. 1.39 rnBAUCHSPECK 1,19 rnBAUCHSPECK 1,19 rnDORNFELDER 0,99rnCLEMENTINEN 2,49rnL&M BLUE 3,50rnL&M BLUE 3,50rnSUMME EUR 14,84 *rnBAR 50,00rnrnRUCKGELD EUR 35,16rn“ENTHALTENE MEHRWERTSTEUER ArnMWST NETTOrn7,00 % 0,45 6,40rn19,00 % 1,28 6,71rnSUMME MWST 1,73 13,11rnEDEKA HANDELSGFSELLSCHAFTrnNORDBAYERN-SACHSEN-THURINGEN MBHrnSTEUERNUMMER: 257/115/30471rnQUITTUNGrnNUTZEN SIE DIF EDECARDrnPUNKTE_SAMMELN+PRAMIEN ERWERBENrnTHR EINKAUF WARE UNSrn1 BONUSPUNKTE WERT GEWESEN !rn08.12.07 16:27 37589 48 4 8500rnFS BEDIENTE STE: H. SEUFERT :rnVIELEN DANK FÜR IHREN EINKAUF!rnAUF WIEDERSEHEN IM E-CENTERrnUNSERE ÖFFNUNGSZEITEN FÜR SIE:rnMONTAG-SAMSTAG: 0800-20 . 00UER";
var rx = /(?:^|[^.d])(d1,2[,.]d2)(?![.d])/g;
var m, res = ;
while (m = rx.exec(text))
res.push(m[1]);
console.log(res);You may use
/(?:^|[^.d])(d1,2[,.]d2)(?![.d])/g
and grab the contents of Group 1. See the regex demo.
Details
(?:^|[^.d])- start of string or any char other than.and digit(d1,2[,.]d2)- Group 1: 1 or 2 digits,.or,, two digits(?![.d])- no.or digit immediately to the right is allowed.
JS demo:
var text = "BT em rnSCHWEINFURT _OSKAR-VON-MILLER-STR.6 rnRADIESCHEN 0,59 rnKAESEAUFSCH. 1.39 rnBAUCHSPECK 1,19 rnBAUCHSPECK 1,19 rnDORNFELDER 0,99rnCLEMENTINEN 2,49rnL&M BLUE 3,50rnL&M BLUE 3,50rnSUMME EUR 14,84 *rnBAR 50,00rnrnRUCKGELD EUR 35,16rn“ENTHALTENE MEHRWERTSTEUER ArnMWST NETTOrn7,00 % 0,45 6,40rn19,00 % 1,28 6,71rnSUMME MWST 1,73 13,11rnEDEKA HANDELSGFSELLSCHAFTrnNORDBAYERN-SACHSEN-THURINGEN MBHrnSTEUERNUMMER: 257/115/30471rnQUITTUNGrnNUTZEN SIE DIF EDECARDrnPUNKTE_SAMMELN+PRAMIEN ERWERBENrnTHR EINKAUF WARE UNSrn1 BONUSPUNKTE WERT GEWESEN !rn08.12.07 16:27 37589 48 4 8500rnFS BEDIENTE STE: H. SEUFERT :rnVIELEN DANK FÜR IHREN EINKAUF!rnAUF WIEDERSEHEN IM E-CENTERrnUNSERE ÖFFNUNGSZEITEN FÜR SIE:rnMONTAG-SAMSTAG: 0800-20 . 00UER";
var rx = /(?:^|[^.d])(d1,2[,.]d2)(?![.d])/g;
var m, res = ;
while (m = rx.exec(text))
res.push(m[1]);
console.log(res);var text = "BT em rnSCHWEINFURT _OSKAR-VON-MILLER-STR.6 rnRADIESCHEN 0,59 rnKAESEAUFSCH. 1.39 rnBAUCHSPECK 1,19 rnBAUCHSPECK 1,19 rnDORNFELDER 0,99rnCLEMENTINEN 2,49rnL&M BLUE 3,50rnL&M BLUE 3,50rnSUMME EUR 14,84 *rnBAR 50,00rnrnRUCKGELD EUR 35,16rn“ENTHALTENE MEHRWERTSTEUER ArnMWST NETTOrn7,00 % 0,45 6,40rn19,00 % 1,28 6,71rnSUMME MWST 1,73 13,11rnEDEKA HANDELSGFSELLSCHAFTrnNORDBAYERN-SACHSEN-THURINGEN MBHrnSTEUERNUMMER: 257/115/30471rnQUITTUNGrnNUTZEN SIE DIF EDECARDrnPUNKTE_SAMMELN+PRAMIEN ERWERBENrnTHR EINKAUF WARE UNSrn1 BONUSPUNKTE WERT GEWESEN !rn08.12.07 16:27 37589 48 4 8500rnFS BEDIENTE STE: H. SEUFERT :rnVIELEN DANK FÜR IHREN EINKAUF!rnAUF WIEDERSEHEN IM E-CENTERrnUNSERE ÖFFNUNGSZEITEN FÜR SIE:rnMONTAG-SAMSTAG: 0800-20 . 00UER";
var rx = /(?:^|[^.d])(d1,2[,.]d2)(?![.d])/g;
var m, res = ;
while (m = rx.exec(text))
res.push(m[1]);
console.log(res);var text = "BT em rnSCHWEINFURT _OSKAR-VON-MILLER-STR.6 rnRADIESCHEN 0,59 rnKAESEAUFSCH. 1.39 rnBAUCHSPECK 1,19 rnBAUCHSPECK 1,19 rnDORNFELDER 0,99rnCLEMENTINEN 2,49rnL&M BLUE 3,50rnL&M BLUE 3,50rnSUMME EUR 14,84 *rnBAR 50,00rnrnRUCKGELD EUR 35,16rn“ENTHALTENE MEHRWERTSTEUER ArnMWST NETTOrn7,00 % 0,45 6,40rn19,00 % 1,28 6,71rnSUMME MWST 1,73 13,11rnEDEKA HANDELSGFSELLSCHAFTrnNORDBAYERN-SACHSEN-THURINGEN MBHrnSTEUERNUMMER: 257/115/30471rnQUITTUNGrnNUTZEN SIE DIF EDECARDrnPUNKTE_SAMMELN+PRAMIEN ERWERBENrnTHR EINKAUF WARE UNSrn1 BONUSPUNKTE WERT GEWESEN !rn08.12.07 16:27 37589 48 4 8500rnFS BEDIENTE STE: H. SEUFERT :rnVIELEN DANK FÜR IHREN EINKAUF!rnAUF WIEDERSEHEN IM E-CENTERrnUNSERE ÖFFNUNGSZEITEN FÜR SIE:rnMONTAG-SAMSTAG: 0800-20 . 00UER";
var rx = /(?:^|[^.d])(d1,2[,.]d2)(?![.d])/g;
var m, res = ;
while (m = rx.exec(text))
res.push(m[1]);
console.log(res);answered Nov 9 at 9:27
Wiktor Stribiżew
306k16125202
306k16125202
1
Thank you so much for your response, it worked :)
– Th0rne
Nov 9 at 9:52
@Th0rne Note that the other posted solution is not generic and you might need to adjust it later to exclude more and more contexts while my solution handles next to all edge cases. If you do not want to match numbers glued to words, just add word boundaries,/(?:^|[^.d])b(d1,2[,.]d2)b(?![.d])/g
– Wiktor Stribiżew
Nov 9 at 9:59
add a comment |
1
Thank you so much for your response, it worked :)
– Th0rne
Nov 9 at 9:52
@Th0rne Note that the other posted solution is not generic and you might need to adjust it later to exclude more and more contexts while my solution handles next to all edge cases. If you do not want to match numbers glued to words, just add word boundaries,/(?:^|[^.d])b(d1,2[,.]d2)b(?![.d])/g
– Wiktor Stribiżew
Nov 9 at 9:59
1
1
Thank you so much for your response, it worked :)
– Th0rne
Nov 9 at 9:52
Thank you so much for your response, it worked :)
– Th0rne
Nov 9 at 9:52
@Th0rne Note that the other posted solution is not generic and you might need to adjust it later to exclude more and more contexts while my solution handles next to all edge cases. If you do not want to match numbers glued to words, just add word boundaries,
/(?:^|[^.d])b(d1,2[,.]d2)b(?![.d])/g– Wiktor Stribiżew
Nov 9 at 9:59
@Th0rne Note that the other posted solution is not generic and you might need to adjust it later to exclude more and more contexts while my solution handles next to all edge cases. If you do not want to match numbers glued to words, just add word boundaries,
/(?:^|[^.d])b(d1,2[,.]d2)b(?![.d])/g– Wiktor Stribiżew
Nov 9 at 9:59
add a comment |
up vote
1
down vote
One way could be to use an alternation to match the format that you don't want and then capture in a group what you do want:
d+.d+.d+|(d1,2[.,]d1,2)
Explanation
d+.d+.d+Match pattern that you don't want to capture (or for exampled2.d2.d2if you want to be more specific)|Or(d1,2[.,]d2)Capture in a group 1 or 2 digits, a comma or dot and then 2 digits
Regex demo
const regex = /d+.d+.d+|(d1,2[.,]d2)/g;
const str = `BT em
SCHWEINFURT _OSKAR-VON-MILLER-STR.6
RADIESCHEN 0,59
KAESEAUFSCH. 1.39
BAUCHSPECK 1,19
BAUCHSPECK 1,19
DORNFELDER 0,99
CLEMENTINEN 2,49
L&M BLUE 3,50
L&M BLUE 3,50
SUMME EUR 14,84 *
BAR 50,00
RUCKGELD EUR 35,16
“ENTHALTENE MEHRWERTSTEUER A
MWST NETTO
7,00 % 0,45 6,40
19,00 % 1,28 6,71
SUMME MWST 1,73 13,11
EDEKA HANDELSGFSELLSCHAFT
NORDBAYERN-SACHSEN-THURINGEN MBH
STEUERNUMMER: 257/115/30471
QUITTUNG
NUTZEN SIE DIF EDECARD
PUNKTE_SAMMELN+PRAMIEN ERWERBEN
THR EINKAUF WARE UNS
1 BONUSPUNKTE WERT GEWESEN !
08.12.07 16:27 37589 48 4 8500
FS BEDIENTE STE: H. SEUFERT :
VIELEN DANK FÜR IHREN EINKAUF!
AUF WIEDERSEHEN IM E-CENTER
UNSERE ÖFFNUNGSZEITEN FÜR SIE:
MONTAG-SAMSTAG: 0800-20 . 00UER`;
let m;
while ((m = regex.exec(str)) !== null)
if (m.index === regex.lastIndex)
regex.lastIndex++;
if (m[1])
console.log(m[1]);
1
Thank you so much. I wasn't really are of the different groups and that is really helpful.
– Th0rne
Nov 9 at 9:51
add a comment |
up vote
1
down vote
One way could be to use an alternation to match the format that you don't want and then capture in a group what you do want:
d+.d+.d+|(d1,2[.,]d1,2)
Explanation
d+.d+.d+Match pattern that you don't want to capture (or for exampled2.d2.d2if you want to be more specific)|Or(d1,2[.,]d2)Capture in a group 1 or 2 digits, a comma or dot and then 2 digits
Regex demo
const regex = /d+.d+.d+|(d1,2[.,]d2)/g;
const str = `BT em
SCHWEINFURT _OSKAR-VON-MILLER-STR.6
RADIESCHEN 0,59
KAESEAUFSCH. 1.39
BAUCHSPECK 1,19
BAUCHSPECK 1,19
DORNFELDER 0,99
CLEMENTINEN 2,49
L&M BLUE 3,50
L&M BLUE 3,50
SUMME EUR 14,84 *
BAR 50,00
RUCKGELD EUR 35,16
“ENTHALTENE MEHRWERTSTEUER A
MWST NETTO
7,00 % 0,45 6,40
19,00 % 1,28 6,71
SUMME MWST 1,73 13,11
EDEKA HANDELSGFSELLSCHAFT
NORDBAYERN-SACHSEN-THURINGEN MBH
STEUERNUMMER: 257/115/30471
QUITTUNG
NUTZEN SIE DIF EDECARD
PUNKTE_SAMMELN+PRAMIEN ERWERBEN
THR EINKAUF WARE UNS
1 BONUSPUNKTE WERT GEWESEN !
08.12.07 16:27 37589 48 4 8500
FS BEDIENTE STE: H. SEUFERT :
VIELEN DANK FÜR IHREN EINKAUF!
AUF WIEDERSEHEN IM E-CENTER
UNSERE ÖFFNUNGSZEITEN FÜR SIE:
MONTAG-SAMSTAG: 0800-20 . 00UER`;
let m;
while ((m = regex.exec(str)) !== null)
if (m.index === regex.lastIndex)
regex.lastIndex++;
if (m[1])
console.log(m[1]);
1
Thank you so much. I wasn't really are of the different groups and that is really helpful.
– Th0rne
Nov 9 at 9:51
add a comment |
up vote
1
down vote
up vote
1
down vote
One way could be to use an alternation to match the format that you don't want and then capture in a group what you do want:
d+.d+.d+|(d1,2[.,]d1,2)
Explanation
d+.d+.d+Match pattern that you don't want to capture (or for exampled2.d2.d2if you want to be more specific)|Or(d1,2[.,]d2)Capture in a group 1 or 2 digits, a comma or dot and then 2 digits
Regex demo
const regex = /d+.d+.d+|(d1,2[.,]d2)/g;
const str = `BT em
SCHWEINFURT _OSKAR-VON-MILLER-STR.6
RADIESCHEN 0,59
KAESEAUFSCH. 1.39
BAUCHSPECK 1,19
BAUCHSPECK 1,19
DORNFELDER 0,99
CLEMENTINEN 2,49
L&M BLUE 3,50
L&M BLUE 3,50
SUMME EUR 14,84 *
BAR 50,00
RUCKGELD EUR 35,16
“ENTHALTENE MEHRWERTSTEUER A
MWST NETTO
7,00 % 0,45 6,40
19,00 % 1,28 6,71
SUMME MWST 1,73 13,11
EDEKA HANDELSGFSELLSCHAFT
NORDBAYERN-SACHSEN-THURINGEN MBH
STEUERNUMMER: 257/115/30471
QUITTUNG
NUTZEN SIE DIF EDECARD
PUNKTE_SAMMELN+PRAMIEN ERWERBEN
THR EINKAUF WARE UNS
1 BONUSPUNKTE WERT GEWESEN !
08.12.07 16:27 37589 48 4 8500
FS BEDIENTE STE: H. SEUFERT :
VIELEN DANK FÜR IHREN EINKAUF!
AUF WIEDERSEHEN IM E-CENTER
UNSERE ÖFFNUNGSZEITEN FÜR SIE:
MONTAG-SAMSTAG: 0800-20 . 00UER`;
let m;
while ((m = regex.exec(str)) !== null)
if (m.index === regex.lastIndex)
regex.lastIndex++;
if (m[1])
console.log(m[1]);
One way could be to use an alternation to match the format that you don't want and then capture in a group what you do want:
d+.d+.d+|(d1,2[.,]d1,2)
Explanation
d+.d+.d+Match pattern that you don't want to capture (or for exampled2.d2.d2if you want to be more specific)|Or(d1,2[.,]d2)Capture in a group 1 or 2 digits, a comma or dot and then 2 digits
Regex demo
const regex = /d+.d+.d+|(d1,2[.,]d2)/g;
const str = `BT em
SCHWEINFURT _OSKAR-VON-MILLER-STR.6
RADIESCHEN 0,59
KAESEAUFSCH. 1.39
BAUCHSPECK 1,19
BAUCHSPECK 1,19
DORNFELDER 0,99
CLEMENTINEN 2,49
L&M BLUE 3,50
L&M BLUE 3,50
SUMME EUR 14,84 *
BAR 50,00
RUCKGELD EUR 35,16
“ENTHALTENE MEHRWERTSTEUER A
MWST NETTO
7,00 % 0,45 6,40
19,00 % 1,28 6,71
SUMME MWST 1,73 13,11
EDEKA HANDELSGFSELLSCHAFT
NORDBAYERN-SACHSEN-THURINGEN MBH
STEUERNUMMER: 257/115/30471
QUITTUNG
NUTZEN SIE DIF EDECARD
PUNKTE_SAMMELN+PRAMIEN ERWERBEN
THR EINKAUF WARE UNS
1 BONUSPUNKTE WERT GEWESEN !
08.12.07 16:27 37589 48 4 8500
FS BEDIENTE STE: H. SEUFERT :
VIELEN DANK FÜR IHREN EINKAUF!
AUF WIEDERSEHEN IM E-CENTER
UNSERE ÖFFNUNGSZEITEN FÜR SIE:
MONTAG-SAMSTAG: 0800-20 . 00UER`;
let m;
while ((m = regex.exec(str)) !== null)
if (m.index === regex.lastIndex)
regex.lastIndex++;
if (m[1])
console.log(m[1]);
const regex = /d+.d+.d+|(d1,2[.,]d2)/g;
const str = `BT em
SCHWEINFURT _OSKAR-VON-MILLER-STR.6
RADIESCHEN 0,59
KAESEAUFSCH. 1.39
BAUCHSPECK 1,19
BAUCHSPECK 1,19
DORNFELDER 0,99
CLEMENTINEN 2,49
L&M BLUE 3,50
L&M BLUE 3,50
SUMME EUR 14,84 *
BAR 50,00
RUCKGELD EUR 35,16
“ENTHALTENE MEHRWERTSTEUER A
MWST NETTO
7,00 % 0,45 6,40
19,00 % 1,28 6,71
SUMME MWST 1,73 13,11
EDEKA HANDELSGFSELLSCHAFT
NORDBAYERN-SACHSEN-THURINGEN MBH
STEUERNUMMER: 257/115/30471
QUITTUNG
NUTZEN SIE DIF EDECARD
PUNKTE_SAMMELN+PRAMIEN ERWERBEN
THR EINKAUF WARE UNS
1 BONUSPUNKTE WERT GEWESEN !
08.12.07 16:27 37589 48 4 8500
FS BEDIENTE STE: H. SEUFERT :
VIELEN DANK FÜR IHREN EINKAUF!
AUF WIEDERSEHEN IM E-CENTER
UNSERE ÖFFNUNGSZEITEN FÜR SIE:
MONTAG-SAMSTAG: 0800-20 . 00UER`;
let m;
while ((m = regex.exec(str)) !== null)
if (m.index === regex.lastIndex)
regex.lastIndex++;
if (m[1])
console.log(m[1]);
const regex = /d+.d+.d+|(d1,2[.,]d2)/g;
const str = `BT em
SCHWEINFURT _OSKAR-VON-MILLER-STR.6
RADIESCHEN 0,59
KAESEAUFSCH. 1.39
BAUCHSPECK 1,19
BAUCHSPECK 1,19
DORNFELDER 0,99
CLEMENTINEN 2,49
L&M BLUE 3,50
L&M BLUE 3,50
SUMME EUR 14,84 *
BAR 50,00
RUCKGELD EUR 35,16
“ENTHALTENE MEHRWERTSTEUER A
MWST NETTO
7,00 % 0,45 6,40
19,00 % 1,28 6,71
SUMME MWST 1,73 13,11
EDEKA HANDELSGFSELLSCHAFT
NORDBAYERN-SACHSEN-THURINGEN MBH
STEUERNUMMER: 257/115/30471
QUITTUNG
NUTZEN SIE DIF EDECARD
PUNKTE_SAMMELN+PRAMIEN ERWERBEN
THR EINKAUF WARE UNS
1 BONUSPUNKTE WERT GEWESEN !
08.12.07 16:27 37589 48 4 8500
FS BEDIENTE STE: H. SEUFERT :
VIELEN DANK FÜR IHREN EINKAUF!
AUF WIEDERSEHEN IM E-CENTER
UNSERE ÖFFNUNGSZEITEN FÜR SIE:
MONTAG-SAMSTAG: 0800-20 . 00UER`;
let m;
while ((m = regex.exec(str)) !== null)
if (m.index === regex.lastIndex)
regex.lastIndex++;
if (m[1])
console.log(m[1]);
edited Nov 9 at 9:43
answered Nov 9 at 9:29
The fourth bird
19.8k71325
19.8k71325
1
Thank you so much. I wasn't really are of the different groups and that is really helpful.
– Th0rne
Nov 9 at 9:51
add a comment |
1
Thank you so much. I wasn't really are of the different groups and that is really helpful.
– Th0rne
Nov 9 at 9:51
1
1
Thank you so much. I wasn't really are of the different groups and that is really helpful.
– Th0rne
Nov 9 at 9:51
Thank you so much. I wasn't really are of the different groups and that is really helpful.
– Th0rne
Nov 9 at 9:51
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2fstackoverflow.com%2fquestions%2f53222893%2fusing-regexp-to-filter-receipt-for-prices%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