[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 438
  • Last Modified:

Java Regular Expressions & BufferedReader

Hello,
I have a 256 char record consisting of fields of varying length with a slash "/" as the field delimiter. With this help of ddrudik, I was able to get past several of the blank fields, but
the matcher fails with the new non-blank fields. I can either make up a very long Expression or try to read  the next known chars that make up the entire record. I am confused as to how to read the "next n chars"  when I am using a bufferredReader as in br.readline(); for the initial read. I have a telemetry stream of data...

Thank You
0
dennisk1718
Asked:
dennisk1718
  • 5
  • 3
1 Solution
 
dennisk1718Author Commented:
Hello,

Reading Friedl leads to a restatement of the problem.

I have a 256 char String to be parsed, with known fields at the 1 thru 12 char positions and at the
184-185 position. The actual discriminator is the field at 184-185 position with some elimination of disqualifying candiates occurring in the 1-12 character postions.
This is a telemtry stream at 9600 bps. Once the stream starts it does not stop. There are no end-of-record indicators in the stream as in "\n", etc. A known byte pattern defines start/end of record of interest.

WI have to recognize the start of the record inthe 1-12 char positions and thenb read to the 184-185 position to check those contents and if a match read to the 256 char position to save the record for parsing.

After a match in the 1-12th position, a region reset to run a usePattern() at 184-185 positon is a possibility?
But how do I read to and save the data over the whole 0-255 char string. ?

Thank You drrudik for your earlier repose and assistance

0
 
ddrudikCommented:
What rules do you use to determine a match at 184-185?  If no match at 184-185 you say you don't read on to 256th char, but do you then discard all 256 chars?  What determines the start of the string?  The fields vary in length but do they vary in quantity per record, and if so, how?
0
 
dennisk1718Author Commented:
Hello,
I have a simple two char match at pos 184-184: The Contents of the Interesting record is marked by the
be two chars AB at 184-185.

Yes, if AB is not found at 184-185 then I pitch the whole 156 chars and move to the next record that starts  with " {6}/ {2}/ {5}/ {2}/". The quantity of fields is fixed at 37 and the field delimieters are the "/" slashes.

Once I read a successful initial set of fields, I need to save the initial set and move to verify the presence of AB in the 184-185 position. If that is a sucess, I need to append the remaining chars out to position 255. I should probably save the intervening fields between the initial set success and the subsequent test at 184-185, as the stream is moving.

I am thinking of a usePattern() for the new match at 184-185.....

Thanks much



0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
dennisk1718Author Commented:
Hello,
Having a fixed number of fields delimited by "/", I have tried to use that fact to move the pointer so
to speak.
So for example, given a successful match at pos 1-12, as described earlier, ther are 26 "/" slashes to the 184-185 postion that constitutes the final check.
My tests on utilizing that piece of inof have not ben successful to date.

Thank You
0
 
ddrudikCommented:
I know little about the nuances of Java or working in it with data streams etc., so my assistance may only be from a regex perspective.

Considering that the string:
" {6}/ {2}/ {5}/ {2}/" (1-19) is the start of your record and it may contain "AB" at 184-185 then continue to 255 if "AB" is found:

The regex pattern (if I counted correctly) should be:
" {6}/ {2}/ {5}/ {2}/.{163}(?:AB.{90})?"
0
 
dennisk1718Author Commented:
Thank You for the ideas...
Most helpful
0
 
ddrudikCommented:
Thanks for the question and the points.
0
 
dennisk1718Author Commented:

Thank You
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now