0

I have a file in notepad with this text as example:

*Given* I get an user ID from XXX
*And* I set header "Authorization" with value "invalid_token"
*When* I send a POST request to api/endpoint/"documentlibraryID"/"identity_id"/root/"new_name"
*Then* the response code should be 401
*And* the response should contain "Invalid authorization token"

*Given* I get an user ID from XXX
*And* I set header "Authorization" with value "YYY"
*When* I send a POST request to api/endpoint/"documentlibraryID"/"identity_id"/root/"new_name"
*Then* the response code should be 200
*And* the response should contain "new_name"

*Given* I get an user ID from "XXX"
*And* I set header "Authorization" with value "YYY"
*When* I send a POST request to api/endpoint/"documentlibraryID"/"identity_id"/root/"folder_name"?automaticRename=true
*Then* the response code should be 200
*And* the response should contain "folder_name 1"

What I need to do: before each word api, i need to insert {code:none} and insert {code} at the end of the line. Example:

api/endpoint/"documentlibraryID"/"identity_id"/root/"folder_name"?automaticRename=true

would be:

{code:none}api/endpoint/"documentlibraryID"/"identity_id"/root/"folder_name"?automaticRename=true{code}

The first part is easy, I would just replace api for {code:none}api in Notepad++. The last part is my problem. Not all lines ends with the same text ... so I would need to find a regex that would Insert {code} at the end of the each line that it finds the word api somewhere, or some other approach ... Not sure if this was clear, I can try to explain better, thanks for any help!

Toto
  • 89,455
  • 62
  • 89
  • 125
ryoishikawa74
  • 177
  • 3
  • 11

2 Answers2

1

Using Notepad++ :

  1. Hit Ctrl+H

  2. In "Find what", type (.*)api(.*)\r

  3. In "Replace with", type \1api\2{code}\r

  4. Check "Search Mode > Regular expression

  5. Hit "Replace All"

Paul W
  • 149
  • 1
  • 6
1
  • Ctrl+H
  • Find what: \bapi\b.*$
  • Replace with: {code:none}$0{code}
  • Replace all

Explanation:

\bapi\b : api not preceeded or followed by word character
.*      : 0 or more any character
$       : end of line
  • DO NOT CHECK . matches newline

Replacement:

{code:none} : literally
$0          : the whole match
{code}      : literally

Result for given example:

*Given* I get an user ID from XXX
*And* I set header "Authorization" with value "invalid_token"
*When* I send a POST request to {code:none}api/endpoint/"documentlibraryID"/"identity_id"/root/"new_name"{code}
*Then* the response code should be 401
*And* the response should contain "Invalid authorization token"

*Given* I get an user ID from XXX
*And* I set header "Authorization" with value "YYY"
*When* I send a POST request to {code:none}api/endpoint/"documentlibraryID"/"identity_id"/root/"new_name"{code}
*Then* the response code should be 200
*And* the response should contain "new_name"

*Given* I get an user ID from "XXX"
*And* I set header "Authorization" with value "YYY"
*When* I send a POST request to {code:none}api/endpoint/"documentlibraryID"/"identity_id"/root/"folder_name"?automaticRename=true{code}
*Then* the response code should be 200
*And* the response should contain "folder_name 1"
Toto
  • 89,455
  • 62
  • 89
  • 125