Reputation: 45
I have a string of 8 separated hexadecimal numbers, such as:
3E%12%3%1F%3E%6%1%19
And I need to check if the number 12
is located within the first 4 set of numbers.
I'm guessing this shouldn't be all that complex, but my searches turned up empty. Regular expressions are always a trouble for me, but I don't have access to anything else in this scenario. Any help would be appreciated.
Upvotes: 0
Views: 242
Reputation: 36101
^([^%]+%){0,3}12%
^
- from the start[^%]+%
- match multiple non % characters, followed by a % character{0,3}
- between 0 and 3 of those12%
- 12%
after thatUpvotes: 2
Reputation: 14089
Here you go
^([^%]*%){4}(?<=.*12.*)
This will match both the following if that is what is intended
1%312%..
1%123%..
Check the solution if %123% is matched or not
If the number 12 should stand on its own then use
^([^%]*%){4}(?<=.*\b12\b.*)
Upvotes: 1