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.
我有这个字符串
s = [notneedtext#neededtext, notneedtext#neededtext, ...]
我应该使用什么正则表达式来仅保留每个元素的所需文本(不带#)并剪切不需要的部分?
#
假设neededtext不包含逗号,您只需要
neededtext
(?<=#)([^,]*)(?=(,|\]))
(?<=#)
([^,]*)
(?=(,|\]))