2017-08-01 57 views
0

我有一個記事本文件,該文本例如:find的正則表達式的幫助和替換

*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" 

我需要做什麼:每個字API之前,我需要插入{code:none}和插入行末的{code}。例如:

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

將是:

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

第一部分是容易的,我只更換爲{代碼:無} API API在記事本++。最後一部分是我的問題。不是所有的行都以相同的文本結束...所以我需要找到一個正則表達式,它將插入{code}在每行的末尾,它找到單詞api某處或其他方法...不知道是否這很清楚,我可以嘗試解釋得更好,謝謝你的幫助!

回答

1

使用記事本++:

  1. 按CTRL + H

  2. 在 「查找內容」 中輸入(.*)api(.*)\r

  3. 在 「替換爲」 中輸入\1api\2{code}\r

  4. 檢查「搜索模式」>正則表達式

  5. 命中 「全部替換」

+0

你是男人,它的工作就像一個魅力!一旦它允許我將它標記爲在5分鐘內解決:-) – ryoishikawa74

+0

非常歡迎! –

1
  • 按Ctrl + H^
  • 查找內容:\bapi\b.*$
  • 替換爲:{code:none}$0{code}
  • 更換所有

說明:

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

更換:

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

結果對於給定的例子:

*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"