-2

I'm looking regex that not include the beginning string (this part I get fine) and exclude the final string that sometimes has a number xxx,xx or has two numbers xxx,xx xxx,xx (see the image).

But my expression - (?<=[0-3][0-9] [0-1][0-9] [2][2-9] 7[\d]{3} ).*(?= [\d]{1,5},[\d]{2} ?([\d]{1,5},[\d]{2})?) fails in case like this:

23 06 22 7314 VIAJES EL CORTE INGL 13389,00 5357,15

I can not exclude 13389,00. Can somebody help me?

See my regex playground.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question – xehpuk Jul 17 '22 at 23:11
  • As per the [ask], please [**do not** post images of code, data, error message, etc](https://meta.stackoverflow.com/questions/285551). Instead, copy or type the text into your question, [formatted as code](https://meta.stackoverflow.com/questions/251361#251362). Reserve the use of images for diagrams or demonstrating rendering bugs; things that are impossible to describe accurately via text. – Bohemian Jul 17 '22 at 23:12
  • while it isn't clear what you're trying to do here (you need to provide a code snippet, or at least some examples of what it should match), the pattern will surely work better if that middle "wildcard" is non-greedy: `.*?` – Scott Weaver Jul 17 '22 at 23:24
  • `(?<=[0-3][0-9] [0-1][0-9] [2][2-9] 7[\d]{3})\s(.*?)\s(?:\d{1,5}\,\d{2})` – nulladdr Jul 17 '22 at 23:56

1 Answers1

0

According to your question and the attached screenshot, I think if your input is:

case-I: 'VAIAJES EL CORTE INGL 13389,00 5357,15'; then output: 13389,00

case-II: 'VAIAJES EL CORTE INGL 13389,00'; then output: 13389,00

This is my understanding, if not then please correct me and describe it properly.

Use regular expression ("Positive Lookahead"): /(?<=[\w+\s+])(\d+\,\d+)/gi to filter the number in format '(\d+,\d+)'.

and used the regular expression as: text.match(/(?<=[\w+\s+])(\d+\,\d+)/gi)?.length ? text.match(/(?<=[\w+\s+])(\d+\,\d+)/gi)[0] : null enter image description here

If you want to get first numbers in this input: 'VAIAJES EL CORTE INGL 13389,00 5357,15'

Then use the regular expression (Lookahead and Lookbehind) like: /(?<=[\w+\s+])(\d+\,\d+)(?=([\d+\,]+\s))/gi enter image description here

Art Bindu
  • 769
  • 4
  • 14
  • Sorry, I did a mistake. I want get only the phrase "VIAJES EL CORTE INGLES". I want discard 13389,00 5357,15 or 13389,00. My regex discard correctly if has only 13389,00 but when contains 13389,00 5357,15 I get the phrase VIAJES EL CORTE INGLES 13389,00" – Sapi Software Jul 18 '22 at 16:50
  • 1
    Use regular expression: `/[a-z ]+(?=(\s[0-9\,]+))/gi` to get only text. ``` 'VAIAJES EL CORTE INGL 13389,00 5357,15'.match(/[a-z ]+(?=(\s[0-9\,]+))/gi) output: ['VAIAJES EL CORTE INGL'] 'VAIAJES EL CORTE INGL 13389,00'.match(/[a-z ]+(?=(\s[0-9\,]+))/gi) output: ['VAIAJES EL CORTE INGL'] ``` – Art Bindu Jul 19 '22 at 05:16