简体   繁体   English

逗号分隔文本的正则表达式,但不包含数字

[英]Regular expression for comma separated text but not surround with digits

I need to split the text with comma separated but not with surround digit like below我需要用逗号分隔而不是像下面这样用环绕数字分割文本

Text is LOCAL_GUA_CONTRACT_AMT NUMBER(22,3) , LOCAL_GUA_CONTRACT_AMT NUMBER(22,3)文字是LOCAL_GUA_CONTRACT_AMT NUMBER(22,3) , LOCAL_GUA_CONTRACT_AMT NUMBER(22,3)

and output is LOCAL_GUA_CONTRACT_AMT NUMBER(22,3)和输出是LOCAL_GUA_CONTRACT_AMT NUMBER(22,3)
LOCAL_GUA_CONTRACT_AMT NUMBER(22,3)

Use this regex: (?<=[^0-9]),(?=[^0-9])使用这个正则表达式:(?<=[^0-9]),(?=[^0-9])

text.split("(?<=[^0-9]),(?=[^0-9])")

it will split with comma as a separator but never if numbers are next to it.它将以逗号作为分隔符进行拆分,但如果旁边有数字,则永远不会拆分。 But it will leave whitespaces as they were但它会留下空白

And if you want whitespaces to be deleted also, use this如果您还想删除空格,请使用此

(?<=[^0-9])\s*,\s*(?=[^0-9])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM