正则表达式从Hive中的字符串前导零

时间:2015-08-13 18:03:16

标签: regex hive

我在PFFile *profile = user[@"profilePic"]; if (profile) { [profile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) { if (!error) { UIImage *profilePic = [UIImage imageWithData:imageData]; //Here is your image use it } else { //error } }]; } 中有一个19个字符的字符串,我需要拆分并删除任何前导零。

示例

Hive

我需要像这样分开它

7212092180052740029

所以第1,第2或第3部分没有前导零,721 20 9218 00527 40029 将从第4部分删除;第5条将被忽视。我想要的结果是

00

我的第一步解决方案是

721209218527

但这似乎极端矫枉过正。任何想法如何用一行正则表达式做到这一点?

另外,应该注意的是,在5个部分中的任何部分中,当分割时,永远不会全部为零(即第1部分永远不会是trim(concat_ws('', regexp_replace(substr(some_string, 1, 3), '^0*', '') , regexp_replace(substr(some_string, 4, 2), '^0*', '') , regexp_replace(substr(some_string, 6, 4), '^0*', '') , regexp_replace(substr(some_string, 10, 5), '^0*', ''))) );如果是这样,那么我的解决方案'不会工作,因为所有零将成为领先者,而000将不会返回任何内容。

1 个答案:

答案 0 :(得分:1)

^0*|(?<=^.{3})0*|(?<=^.{5})0*|(?<=^.{9})0*|(?<=^.{14}).*$

您可以使用此正则表达式并替换为empty string。请参阅演示。

https://regex101.com/r/rO0yD8/15

相关问题