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.
如何通过正则表达式从名称 = 值格式的字符串中提取名称?我想从字符串中获取
saf asfgo = ==slwin[(*]? m||a=vd8228J)_+ sPiof+_ = vsfs=+":~lue3
只有名字:
saf asfgo m||a sPiof+_
没有第一个等于符号和它前面的空格。
更新。我尝试使用^.+(?=[ \t]*?=) upd2。对不起。我很快找到了决定:^.+?(?=[ \t]*=)
^.+(?=[ \t]*?=)
^.+?(?=[ \t]*=)
尝试这个
if ($subject =~ m/(?im)^([^=\r\n]+?)\s*=\s*([^=\r\n]+?)$/) { $name = $1; $value = $2; } else { $name = ""; $value = ""; }