簡體   English   中英

如何查找以#使用RegEx開頭的字符串中的文件名

[英]How can I find File name in string which start with # Using RegEx

我有字符串:

" testfile.txt #testfile.txt
  My new message
Filename1.doc #filename.doc"

如何找到以“#”開頭的文件名並將其從字符串中刪除

試試這個:

var pattern = @"\#[\w,\s-]+\.[A-Za-z]+\s*";
var result = Regex.Replace(
            "testfile.txt #testfile.txt My new message Filename1.doc #filename.doc",
            pattern, string.Empty);

結果:

 "testfile.txt  My new message Filename1.doc "

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM