Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
"-dhello;-egoodbye;-lcul8r" -replace "-d.*;","-dbonjour;"
给出:
-dbonjour;-lcul8r
有可能不让它摆脱goodbye吗?
goodbye
您应该使用?.
?
采用:
"-dhello;-egoodbye;-lcul8r" -replace "-d.*?;","-dbonjour;"
始终明确。.*匹配它可以匹配的所有内容(包括分号和后面的所有内容),但您只想匹配到下一个分号,所以只需告诉正则表达式引擎:
.*
"-dhello;-egoodbye;-lcul8r" -replace "-d[^;]*;","-dbonjour;"
[^;]匹配除 分号以外的任何字符。
[^;]