简体   繁体   中英

Match resulting String using regex

I have a string 00408-B193AQ-P-DW-11045 which is a TAG of Pipe. Using regex I want to match only B193AQ-DW-11045 .Using global option I am able to get the required using regex [AZ][0-9a-zA-Z][^P]+ . But ours system supports ignore case (not global). So with ignore case need a regex which gives the required result.

If You check programmatically You could broke into named groups:

(?'index'[\d]{5})-(?'index1'[0-9a-zA-Z]{6})-(?'index3'[A-Z])-(?'index4'[A-Z]{2})-(?'index5'[0-9]{5})

Returns:

index: 00408
index1: B193AQ
index3: P
index4: DW
index5: 11045

If just check for matching some of parts try use this pattern:

.{5}-([0-9a-zA-Z]{6})-.-([A-Z]{2})-([0-9]{5})

Here '.' (dot) means any character

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