我試圖找出一個正則表達式,將符合下列條件:什麼RegEx會清理這組輸入?
.../string-with-no-spaces
- >string-with-no-spaces
或
string-with-no-spaces:...
- >string-with-no-spaces
或
.../string-with-no-spaces:...
- >string-with-no-spaces
那裏......可以是任何東西在這些例子字符串:
example.com:8080/string-with-no-spaces:latest
string-with-no-spaces:latest
example.com:8080/string-with-no-spaces
string-with-no-spaces
和獎金將
http://example.com:8080/string-with-no-spaces:latest
和所有將匹配string-with-no-spaces
。
是否有可能爲一個單一的正則表達式來涵蓋所有這些情況?
到目前爲止,我已經儘可能/\/.+(?=:)/
得到但這不僅包括斜槓,但只適用於情況3.任何想法?
編輯:我還想說,我使用Node.js的,所以理想的解決方案應該通過所有這些:https://jsfiddle.net/ys0znLef/
有什麼東西永遠在那裏確定? –
只有'沒有空格的字符串'。如果知道正則表達式並且可以將我需要的正則表達式轉換成英語,那麼它將是「刪除http://如果它存在,那麼在斜槓前刪除所有內容(如果有的話),然後在冒號後刪除所有內容。 –