简体   繁体   中英

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. 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)"? 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).

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?

Edit:

Thanks everyone in the comments, your feedback really helped me out!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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