drew
drew

Reputation: 140

Simple Java regex

Finding Java tedious after Python. Looking to parse some base64 concated data.

How do I split a simple string on one or more equals '='?

What is wrong with this simple regex? (it's Java codebase under the Jython hood)

>>> s = "hello=world"
>>> s.split("=+")
['hello=world']
>>> s.split("=*")
['hello=world']
>>> s.split("=")
['hello', 'world']

Upvotes: 2

Views: 114

Answers (3)

James Anderson
James Anderson

Reputation: 27478

Interesting problem!

Your code is valid Java syntax for splitting.

BUT

You are using Jython and Jython string.split() splits on character string not a regex.

You need to use the Jython re.split to break up the string.

Upvotes: 4

progrenhard
progrenhard

Reputation: 2363

Are you talking about this?

  ^([a-zA-Z0-9]*)=*([a-zA-Z0-9]*)$

Regular expression visualization

Edit live on Debuggex

Upvotes: 0

drew
drew

Reputation: 140

Just an issue with Jython. FYI

Input

        decryptKeySplits("Testing=hello");
        decryptKeySplits("Testing====hello");
        decryptKeySplits("Testing=hello==");
        decryptKeySplits("Testing=hello=this=it");

Results

2
2
2
4

Upvotes: 0

Related Questions