-1

I have a string with hex values, for example:

01 02 03 AA BB CC FF 09 65 AA BB DE F2

And my need is take part of this string before first AA BB. I try do it with regular expressions. My ideas are around something like this:

(([0-9A-F]{2} )+(AA BB )){1}

And after match take first group. But it's not works. Could somebody help me with this task, please?

Aave
  • 548
  • 1
  • 5
  • 15

2 Answers2

0

My guess is that your designed expression seems to be fine, maybe this slight modification

^([0-9A-F]{2}\s?)+(?=\sAA BB).*$

might work.

Demo 1

Or if we wouldn't be validating, maybe these expressions would work:

^(.+?)(?=\sAA BB).*$

Demo 2

^(.+?)(?:\sAA BB.*)$

Demo 3


Edit

Or if the pattern might be repeating:

(.+?)(?:\sAA BB\s*.*?)

Demo 4

Emma
  • 27,428
  • 11
  • 44
  • 69
  • 1
    This pattern "01 02 03 AA BB CC FF" may be just start of a string, and string may be longer. Also, "AA BB" may be presented further in a string. I need part before first "AA BB" in the string. Your solution is not working for me, sorry... – Aave Jul 03 '19 at 20:53
0

If you change that regex to (([0-9A-F]{2}\s)+)(AA BB ) you can capture "01 02 03" in the first group