提取字符串,然后使用REGEX进行空间的数字
follwing字符串
[1] weight | width | depth | 5.0 kg | 6.0 mm^3 | 10.12 cm^2
我只需要从中提取单元字符串的
unit=kg
unit=mm^3
unit=cm^2
,但我也尝试了以下正则弦
(?<unit>[^ -+0-9\\.\|\[\}\]]+)
,但它也给出了重量,宽度,深度值。也尝试过
(?<unit>[\D][^|]+)
但不起作用。 我想我需要提取随后是数字和空间的字符串,
您可以帮助我
I have the follwing string
[1] weight | width | depth | 5.0 kg | 6.0 mm^3 | 10.12 cm^2
From that I need to extract the unit strings only
unit=kg
unit=mm^3
unit=cm^2
I tried the below regex
(?<unit>[^ -+0-9\\.\|\[\}\]]+)
But it is also giving the weight,width,depth values too. Also tried
(?<unit>[\D][^|]+)
but not worked.
I think I need to extract the strings which are followed by number and space
Can you help me on this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用字符类列出允许的字符:
regex demo
或更具体:
请参阅另一个 regex demo
如果应该有管道或字符串的末端:
Regex Demo
You could use a character class to list the allowed characters:
Regex demo
Or more specific:
See another regex demo
If there should be either a pipe or the end of the string:
Regex demo
我使用了以下以下等级,它仅匹配单元字符串。
演示链接: https://regex101.com/r/ajonqr/ajonqr/1
I have used below regex, and it is matching only unit string.
Demo link : https://regex101.com/r/AjONqR/1