简体   繁体   中英

Regex pattern to split using either '==' or '='

The idea is to split base64 encoded string using '=' or '==' delimiter.

Source text might look like:

Zte+2RAEIEMU/2C6W6udzqkBKOM1Cp1R8tjbA17aAf0HZQ9NPpiJ7eWCA+r0Y00sRYFRwIMG/3IaOamst0WHNbB1QDZktNJxTIW4nYnA93Q=
Zte+2RAEIEMU/2C6W6udzqkBKOM1Cp1R8tjbA17aAf2yK8KmrbIGVD8vOyZj4uVg579ehXm9OrUsDebQ9C7OAg==

I have tried to use (?<==) for .split() method, but as you understand it leaves '=' empty string. In case of (?<=\\b[=]) - same issue, but second '=' in some cases removed.

The idea is to write something like "either use single '=' that has any character excluding '=' before and after, or use double '==' using same conditions. However, no success with this one.

You have two Base64 encoded chunks of data, which are separated by a new line. You should split the string at the line break character. You can NOT rely on the existence of "=", since this is just for padding the last two bytes if neccessary. Sometimes there is one "=", sometimes there are two "==" and sometimes you will not find it at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM