简体   繁体   中英

PCRE - perl regex

I am trying to make an regex in PCRE for string detection. The kind of strings I want to detect are abcdef001, zxyabc003. A word with first 6 characters are a-zA-Z and last two or three are digits 0-9; and this string could be anywhere in the whole text.

Eg - "User activity from server1, user id abcdef009 , time 10.20am".

How do I go about this?

Try this:

/[a-zA-Z]{6}[0-9]{2,3}/

If you want to limit it to whole words, try:

/\b[a-zA-Z]{6}[0-9]{2,3}\b/
  • \\b - word boundry
  • [a-zA-Z]{6} - six letters
  • [0-9]{2,3} - either 2 or 3 numbers
  • \\b - word boundry

使用正则表达式

/[a-z]{6}\d{2,3}/i

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