0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

文字列を()内のものを除き,で分割する

Posted at

どんな場合でも使える方法ではないですが。

// これを
final String sqlBlock = "a.hoge=:hoge, a.moge=:moge, b.foo=IFNULL(a.foo, 'xxx')";
// このパーツに分解したい
// "a.hoge=:hoge"
// "a.moge=:moge"
// "b.foo=IFNULL(a.foo, 'xxx')"

単に sqlBlock.split(",") でやってしまうと "b.foo=IFNULL(a.foo,"" 'xxx')" に分割されてしまって悲しい。

正規表現の否定後読みを使って

sqlBlock.split("(?<!\([a-zA-Z.]+), ");

これでなんとかなりました。

image.png

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?