0

I have a script that returns strings of the form -

   http-STYPE-CONNECT-new/mydir/20200215_14-30-01/http/PAY_STYPE-CONNECT-new/ "Check for atleast one http 200": Expression '($1=="r" && $13==200)' matched 0 time(s), which is below specified min of 1
   http-PARALLEL-new/mydir/20200215_14-30-01/http/PAY_PARALLEL-new/ "Check for atleast one http 200": Expression '($1=="r" && $13==200)' matched 0 time(s), which is below specified min of 1
   http-STYPE-new/mydir/20200215_14-30-01/http/PAY_STYPE-new/ "Check for atleast one http 200": Expression '($1=="r" && $13==200)' matched 0 time(s), which is below specified min of 1
   http-STYPE-CONNECT-0RTT-new/mydir/20200215_14-30-01/http/PAY_STYPE-CONNECT-0RTT-new/ "Check for atleast one http 200": Expression '($1=="r" && $13==200)' matched 0 time(s), which is below specified min of 1

I would like to split (or apply regex) each string in such a way that everything before the first '/' is stored into variable test_name, everything between the first '/' and last '/' of the path is stored in variable path and everything after the last '/' of the path is stored in the variable failure_reason.

Example:

test_name = http-STYPE-CONNECT-new

path = /mydir/20200215_14-30-01/http/PAY_STYPE-CONNECT-new/

failure_reason = "Check for atleast one http 200": Expression '($1=="r" && $13==200)' matched 0 time(s), which is below specified min of 1

There are two other possibilities that could make the parsing complex -

  1. There could be a \n anywhere between the string. For example: after the last '/' of the path.
  2. There can be a '/' in the string that could appear after the last '/' of the path.

Since i am a novice, i simply tried using the split('/'), join(), strip() functions in python3, but couldn't really manage to get what i wanted to achieve.

Any help would be highly appreciated. Thanks




Ira
  • 399
  • 2
  • 8
  • It looks like there are matching pre and post fix strings. e.g. STYPE-CONNECT-new. Could you extract the prefix and use that to find the postfix as a terminator? – gph Feb 17 '20 at 04:52
  • @gph: Thank you for the hint. The strings (pre) may be different. E.g h2-TYPE1-NA-old. – Ira Feb 17 '20 at 06:11
  • Looks like you are looking to create a regex, but do not know where to get started. Please check [Reference - What does this regex mean](https://stackoverflow.com/questions/22937618) resource, it has plenty of hints. Also, refer to [Learning Regular Expressions](https://stackoverflow.com/a/2759417/3832970) post for some basic regex info. Once you get some expression ready and still have issues with the solution, please edit the question with the latest details and we'll be glad to help you fix the problem. – Wiktor Stribiżew Feb 17 '20 at 09:31

0 Answers0