简体   繁体   English

正则表达式VBA Excel在单元格中查找模式

[英]Regex VBA Excel Finding patterns within a cell

I am currently trying to split up lines of data using excel and VBA with regex to match patterns. 我目前正在尝试使用excel和VBA与正则表达式来拆分数据行以匹配模式。 All of my data is in one column with each row needing to be split into 3 parts. 我所有的数据都放在一列中,每一行都需要分成三部分。

My question pertains to the use of regex and how exactly terms work next to each other and what causes the next term to be used. 我的问题涉及到正则表达式的使用以及各个术语彼此之间如何精确工作以及是什么导致下一个术语被使用。

For instance, I have a line that reads: 例如,我有一行显示:

"([A-Z]{3})(\W{5,})(.+)(\|\d\.\d)"

Should I read this as "Any 3 capitalized letters followed by at least 5 non-word characters, then take everything up to and including bar digit dot bar(no further)"? 我读这为“任何3个大写字母后面至少5个非单词字符,然后采取一切直至并包括酒吧位点吧(没有进一步的)”? Or is the .+ going to just sprawl till the end of my data until it hits a line break? 还是。+会一直蔓延到我的数据结尾,直到遇到换行符?

I guess what I am wondering is if a new term will interupt a previous term (such as with .+ till "|digit.digit" above). 我想我想知道一个新术语是否会插补上一个术语(例如使用。+直到上面的“ | digit.digit”)。

Any assistance in clearing this up for me would be super appreciated, thank you in advance. 在此感谢您为我提供的任何帮助,在此先感谢您。

Edit: Example 编辑:示例

ABC|^-\%!lkaddghlk shfdahah|$^~436346dghdhg|^dgf^356||P|7.7XYZ~^!HYU52

Would this capture only 仅此捕获

ABC|^-\%!lkaddghlk shfdahah|$^~436346dghdhg|^dgf^356||P|7.7

Because the last term is |digit.digit or would it capture everything because of .+ in the 3rd capture group? 因为最后一项是| digit.digit,还是因为第三个捕获组中的。+而捕获了所有内容?

Edit: 编辑:

Thanks everyone in the comments, your feedback really helped me out! 谢谢大家的评论,您的反馈意见确实对我有所帮助!

感谢您的帮助评论者,我现在理解在以上代码中新术语会打断旧术语!

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

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