I’ve been writing a file parser and in the parser I parse each line using a regular expression, if it matches then I parse out the data.
I should admit now, my regex knowledge is basic at best……
So I have a line that looks like this:
( -3456 -3104 344 -24 -10 1 0 0 ) ( -3456 -2976 344 -23 -10 1 0 0 ) ( -3456 -2976 312 -23 -9 1 0 0 )
8 floating point values (above in brackets, repeated n times (3 above, but could me more or fewer).
I tried this:
\( (.*?) \)
Which parsed out the content of the brackets (which I then parsed out using another regex), but that also matched lines like this:
/* iap 0 */ 4 5 1 ( 176 -1272 120 ) ( 176 -1272 264 ) ( 176 -1416 264 ) ( 176 -1416 120 )
Which I didn’t want it to. I guess this is because I don’t specify the start ^
But if I do I only seem to get the 1st set of brackets…
^\( (.*?) \)
I’ve been looking at this for hours, going in circles, but struggling to find what I’m after – pointers/help please?
This will do the trick to distinguish your example:
It’s looking for one or more set of parentheses (brackets) with only numbers, spaces, hyphens (minus signs), and decimal points inside. It also allows whitespace between the sets, and requires that they take up the whole line. If you need it to specifically match only sets of eight numbers, that will look a bit different.