In line

"Теоретики3 и 2п4423рактики палинд4442рома выделили 2многочис2ленные4 погран24ичные2 с пал24инд4ром4м формы" 

find words consisting of numbers and letters.

I can not write a regular expression for the job, it just happened:

 ([a-zA-Zа-яА-ЯёЁ]+\d+[a-zA-Zа-яА-ЯёЁ]+)|(\d+[a-zA-Zа-яА-ЯёЁ]+)|([a-zA-Zа-яА-ЯёЁ]+\d+) 

But then the word пал24инд4ром4м divided into three, and the погран24ичные2 not completely distinguished.

  • one
    Obviously, it is necessary to bind to the edge of the word \ b ... \ b - Evgeny Borisov

2 answers 2

 ((([a-zA-Zа-яА-ЯёЁ]+\d+)|(\d+[a-zA-Zа-яА-ЯёЁ]+))[a-zA-Zа-яА-ЯёЁ\d]*) 

those. ((one or more letters, then one or more numbers) or (one or more numbers, then one or more letters)) then letters or numbers

  • Somehow too much ... - Qwertiy

Regular this (you must set the flag to ignore the register):

 (?=\w*(?!\d)\w)(?=\w*\d)\w+ 

Without underscores:

 \b(?=\w*(?!\d)\w)(?=\w*\d)(?=((?!_)\w)+\b)\w+ 

By the way, no binding to languages ​​:)

http://ideone.com/ZdG7Sa
http://ideone.com/sIsUF4

 using System; using System.Text.RegularExpressions; public class Test { public static void Main() { var str = "Теоретики3 и 2п4423ра_ктики палинд4442рома выделили\n" + "2многочис2ленные4 погран24ичные2 с пал24и_нд4ром4м формы"; foreach (Match match in Regex.Matches(str, @"(?=\w*(?!\d)\w)(?=\w*\d)\w+", RegexOptions.IgnoreCase)) Console.WriteLine(match.Value); Console.WriteLine("==="); foreach (Match match in Regex.Matches(str, @"\b(?=\w*(?!\d)\w)(?=\w*\d)(?=((?!_)\w)+\b)\w+", RegexOptions.IgnoreCase)) Console.WriteLine(match.Value); } } 
  • It will not work, because you need a word of letters and numbers, and the character '_' is still in \ w. - Jagailo
  • @BabaYaga, what's the problem to exclude him? And in general, what he did not please as a letter? - Qwertiy
  • In which alphabet did you see the underscore? - Jagailo
  • @BabaYaga, in any :) (?=((?!_)\w)+)\b - Qwertiy
  • one
    @BabaYaga, the answer is supplemented. - Qwertiy