YunnYDUuGxVxAeLCZuVvSfoutO8

YunnYDUuGxVxAeLCZuVvSfoutO8

This question already has answers here:
How to split a string, but also keep the delimiters?
                                
                                    (23个答案)
                                
                        
                                4个月前关闭。
            
                    
我有这样的字符串

String s = "p=YSp%hZ5=YunnYDUuGxVxAeLCZuVvSfoutO8=";
String[] array = s.split("=");


这个数组将给我这样的输出:p,YSp%hZ5,YunnYDUuGxVxAeLCZuVvSfoutO8

希望具有这些元素,但保留=符号,例如:p =,YSp%hZ5 =,YunnYDUuGxVxAeLCZuVvSfoutO8 =

我需要用=分隔它,然后以某种方式保留'='符号。有谁知道某种模式可以帮助我。

最佳答案

您可以使用此模式...



 s = "p=YSp%hZ5=YunnYDUuGxVxAeLCZuVvSfoutO8=";
array = s.split(/(?<=\=)/);
console.log(array);

10-06 06:22