簡體   English   中英

簡單的Java正則表達式

[英]Simple Java regex

在Python之后找到乏味的Java。 希望解析一些base64精簡數據。

如何在一個或多個等於'='上拆分簡單字符串?

這個簡單的正則表達式有什么問題? (這是Jython的Java代碼庫)

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

有趣的問題!

您的代碼是用於拆分的有效Java語法。

您正在使用Jython和Jython string.split()分割字符串而不是正則表達式。

您需要使用Jython re.split拆分字符串。

你在說這個嗎

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

正則表達式可視化

在Debuggex上實時編輯

Jython只是一個問題。 FYI

輸入

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

結果

2
2
2
4

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM