2011-11-29 3 views
5

숫자가 들어있는 정규식이있는 단어를 어떻게 인식 할 수 있습니까? 그래서 "string1", "12inches", "log4net"을 캡처하고 싶습니다. 하지만 2011 년 12 월 11 일 또는 18 일이 아닌가요? Unfortunetly \b[\p{L}\d\p{M}]+\b 그래도 수치.숫자가 포함 된 단어

답변

2

이 :

Regex regexObj = new Regex(@"\b(?=\S*[a-z])\w+\b", RegexOptions.IgnoreCase); 
    Match matchResults = regexObj.Match(subjectString); 
    while (matchResults.Success) { 
     // matched text: matchResults.Value 
     // match start: matchResults.Index 
     // match length: matchResults.Length 
     matchResults = matchResults.NextMatch(); 
    } 

마음에서 온다.

" 
\b   # Assert position at a word boundary 
(?=   # Assert that the regex below can be matched, starting at this position (positive lookahead) 
    \S   # Match a single character that is a “non-whitespace character” 
     *   # Between zero and unlimited times, as many times as possible, giving back as needed (greedy) 
    [a-z]  # Match a single character in the range between “a” and “z” 
) 
\w   # Match a single character that is a “word character” (letters, digits, etc.) 
    +   # Between one and unlimited times, as many times as possible, giving back as needed (greedy) 
\b   # Assert position at a word boundary 
" 
+0

감사합니다. 실제로 나는 좀 더 어려운 문제가 있습니다 : 공백이나 하이픈으로 구문을 인식하고 이것을 필요로합니다 : (? <= \ b ([\ p {L} \ p {M}] + | \ s) \ b) [\ \ p {Pd} \ s] + (? = \ b [\ p {L} \ p {M}] + \ b). 왼쪽과 오른쪽 괄호는 몇 마디를 의미합니다 (움라우트를 가질 수 있음). 이제 당신은 앞으로 몇 가지 참조를 연결했습니다. – Nickolodeon

+0

@Nickolodeon 제 대답이 대답하기 때문에 당신이 질문을 수정해야한다고 생각합니다. 우리가 도울 수 있도록 적절한 입출력 샘플을 게시하십시오. – FailedDev

+0

글쎄, 미안, 내가 질문을 단순화하고 싶었는데, 그래서 그것의 일부만 물었다. 1) Robocop - 3 => Robocop3이 필요합니다. 2) Hello 2 => Hello2 3) Hello world => Helloworld. 인접한 단어 중 어느 것도 숫자 또는 날짜가 아니면 공백이나 하이픈 btwn 단어를 제거합니다. – Nickolodeon

0

단어와 단어가 일치하도록하고 싶습니까? 이것은 작동해야합니다 : \b(\w+\d+|\d+\w+)[\w\d]+\b.

관련 문제