简体   繁体   中英

Regex help, words that contain numbers without a space

I have been trying for hours now to figure out this regex and it will not work correctly.

What i need is one that will match the following: I need it to match IF any word in the entire description is a character followed by a number, without a space

for example:

MC15 this is a test description - MATCH

MC 15 this is another description - NO MATCH

another test MC55 description - MATCH

another test MC 55 description - NO MATCH

i greatly appreciate any help! thanks for your time!

Can you use "find" instead of "match"? (IE, the regular expression method you call on your pattern - in order to search for a substring instead of matching against the entire input?) If so, this will do nicely:

([a-zA-Z]+\d+)

Otherwise, it can be expanded to work with "match", using something like:

\b*([a-zA-Z]+\d+)\b*

In perl, a regexp like /[a-zA-Z]+\\d+/ would work:

  • [a-zA-Z] denotes any letter
  • \\d denotes any decimal
  • the + after each character class says it has to be present one or more times

(?<aMatch>[a-zA-Z]+[0-9]+)

这一次或多次匹配任何az或AZ字符,然后一次或多次匹配任何数字0-9一次,不允许空格或任何其他字符来分隔它们

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