简体   繁体   中英

regex look ahead operator

I have a string consisting of N- length of special character delimiters, Input: --1-----3--1-2 where once the .split method applied on the pattern should give output as below.

I wish to make a pattern where if the length of delimiter,N is N>1, to get the resulting match as, Output: 1,3,1,-2

Note the last element.

So far I have implemented the use of look ahead operator: (\\W)(?=[\\-{2,}\\d]) giving 1,3,1,2 .

Any feedback is appreciated. Many thanks.

How about: (\\W){2,}

That will give you 131-2 on your input.

https://regex101.com/r/algIJ7/1

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