简体   繁体   中英

Regex to match character in specific position and specific length

I need to find string with length of 12 and contains in the 7 position the char "U".

I have the following strings:

SUPERHUMANLY
DFGDFGDFGGFG
SUPSRHTMANLY
DFGDFGUFGGFG

Only the following should matched:

SUPERHUMANLY
DFGDFGUFGGFG

Following this link I know how to get match on the 7 position:

^.{6}[U]

But I want to get match on only letters with specific length, so I tried ^.{6}[U]{12} , ^(.{6}[U]){12} and ^.{6}[U].{12} without success.

How can I combine the length of the string with the position ?

如何简单:

^.{6}U.{5}$

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