Forum Discussion

vikititor's avatar
vikititor
Contributor
6 years ago

how to write regex to detect end of line??

I am using simple script for reading the LOG file line by line. I need to detect end of line what is \r\n (because windows). Now my LOG message ends with this: "bla bla bla.. status: OK, errors: {}...
  • groovyguy's avatar
    groovyguy
    6 years ago

    I've had to mess around with regex and ReadyAPI and escaping escape characters. It gets really tricky, but I can show you an example I've been working with: 

     

    Here is a standard regex pattern:

    [A-Za-z0-9\.,\(\)\-\+@\?:\s]*

    To make this work in ReadyAPI / groovy, I have to escape it to look like this:

    [A-Za-z0-9\\.,\\(\\)\\-\\+@\\?:\\s]

    I am taking a look at your example line and match pattern and will see if I can figure it out. Can you potentially provide a copy of the log file you are trying to parse? It'll be easier to work with what you have, or a mocked up file of what you need to process. That way I'm working with the closest thing possible to the source. 

  • vikititor's avatar
    vikititor
    6 years ago

    YES.. !!!! :-D

    Why this simple help is not a part of your user guide? I did not found any information about escaping by "\\" nowhere.

    It works!

    I can write simple regex to detect quotes like "\\{\\}" and it matches.

    SO I KNOW, that in between { and } is nothing.. so no problem.

    I can write simple regex to check if end of line is present:

    line.eachMatch("SUCCESS,\\{\\}\\Z")

     

    Thanks a lot. 

    PS: please add this usefull thing in to your WIKI pages.. where your are explaining RegExp in groovy.. will be nice to know.