Minh Giang
Minh Giang

Reputation: 727

Regular expression: Match a string starting with some symbol, continue with left match

I have a long string, for example:

sometext~ZA÷sometext1~textsome1~text~ZA÷sometext2~textsome3~text~.......

I want a array string:

I tried pattern: ZA÷(.*?)~

It's only match ZA÷sometext~, and I've missing result. Anyone help me resolve my problem. I don't know much about regex!

EDIT: That string is just an example. It may be:

ZA÷ACDK¬ZEE÷EcZwBi3N¬ZB÷1¬ZY÷Africa¬ZC÷nyyrdizT¬ZD÷p¬ZE÷QDSL‌​ZVAl¬ZF÷0¬ZO÷0¬ZG÷1¬‌​ZH÷1_EcZwBi3N¬ZJ÷2¬Z‌​L÷/legue¬ZX÷00Africa‌​......006Africa00100‌​00000002000CAF Champion020League000¬~AA÷j3xCaVI8¬AD÷1471966200¬AB÷1¬CR÷1¬AC‌​÷1¬CX÷Enyimba¬AX÷0¬B‌​X÷-1¬WM÷ENY¬AE÷Enyim‌​ba¬WU÷enyimba-intern‌​ational¬WN÷MAM¬AF÷Ma‌​melodi Sundowns¬WV÷mamelodi-sundowns¬AN÷y¬MW÷16|4.........

It's a complex string, which rules

Upvotes: 1

Views: 116

Answers (3)

Minh Giang
Minh Giang

Reputation: 727

My friend give this pattern: (ZA÷((?!ZA÷).)*), it's work well. Thank you all for your help! :D

Upvotes: 0

Mohit S
Mohit S

Reputation: 14064

You can try the following pattern

(ZA÷.*?)ZA÷

The edit string is a sample but it doesn't have repeated ZA÷ thus cannot test it properly. But I m sure this gonna work for you, if it matches the pattern shown above.

EDIT

After getting the full string this seems to be working

.+?(?=ZA÷)

.+? matches any character (except newline)

Quantifier:

+? Between one and unlimited times, as few times as possible, expanding as needed [lazy]

(?=ZA÷) Positive Lookahead - Assert that the regex below can be matched

Upvotes: 0

Mixim
Mixim

Reputation: 972

Just change you pattern to:

"ZA÷(.*?)~(.*?)~(.*?)~"

Upvotes: 1

Related Questions