Android Question Regular Expression

Discussion in 'Android Questions' started by walterf25, Oct 15, 2018.

  1. walterf25

    walterf25 Well-Known Member Licensed User

    Hello All, i need some help figuring out how to write a regular expression to parse a very specific group of data from a large file, I have tried several patterns that I have found online but non of them return the results I'm trying to achieve.
    I have tried the following:
    But again it doesn't return the results i need.
    For example in the image attached i have highlighted the data I need to extract, there are multiple instances of these readings in the file, and the problem is that they are generated at different times depending on a number of events within the firmware, so there isn't really a pattern that I can go by, i have also tried parsing the file line by line and this sort of works but it won't really work 100% as there is another line that I need to look for which could very well happen at the beginning of the file, after a temperature reading or at different random states, so reading line by line is really not the route i would like to stick to, If i could create a regular expression that returns the strings i have highlighted then i could for example parse the lines and check whether the returned group contains for example the word "cam0" if the check returns true then I could somehow go back up to the previous read and extract the temperature readings from this line
    regex.PNG

    Has anyone dealt with this kind of parsing before, i'm really not too familiar with Regular Expressions and i try to avoid it every time i can as I really don't understand much of it, but any help will be greatly appreciated.

    If anyone has any ideas, i can send the file I need to parse in a private message.

    Thanks,
    Walter
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Doesn't sound too complicated. Read the file with File.ReadList. This will allow you to easily go back and forth as needed.
    Don't try to parse it with a single regex.
     
  3. MarkusR

    MarkusR Well-Known Member Licensed User

    i would split it into chunks.
    if u find GetTemperature find start / end behind this key word.
    this block read response, read send:
    read exitcode, read structure name, find start end, read key values for this structure into a map.
    so each sub get a piece of data for processing and return his result in a more handy form.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice