正则表达式c#模式匹配 [英] Regex c# pattern match
问题描述
正则表达式模式(父级):( [Az] {1,}) - ([az] {1,})=此模式找出(例如:午夜)。
正则表达式模式(孩子):需要知道用于查找单词(午夜)和(中午)的正则表达式模式。
我有一段话语。在那篇文章中(午夜,午夜,午夜)这些文字存在,我需要一个正则表达式来匹配这些文字。
请给我一个解决方案。
Regex pattern(parent):([A-z]{1,})-([a-z]{1,})= this pattern finds out(eg:mid-night).
Regex pattern (child): Need to Know regex pattern for finding words(midnight) and (mid night).
I am having a passage with a group of words. In that passage (mid-night,mid night,midnight)these words are present, i need an regex pattern to match these words from passage.
please provide me a solution.
推荐答案
我不确定正则表达式是否正是您在寻找的内容:它不是文本匹配过程,而是模式匹配过程。它无法区分:
I'm not sure that a regex is exactly what you are looking for here: it isn't a text matching process, it's a pattern matching process. It can't tell the difference between:
mid night
和
and
midnight tonight
它们都是一个字后跟一个空格,后跟一个字。
但是如果你想用你的第一个正则表达式找到
They are both "a word" followed by "a space", followed by "a word".
But if you want to find
word-otherword
然后搜索所有出现的任何
with your first regex and then search for all occurrences of any of
word-otherword
word otherword
wordotherword
然后每个人都需要你创建一个单独的正则表达式沿着行:
then each one will need you to create a separate regex along the lines of:
word[\s-]{0,1}otherword
并为你的每对匹配组运行原始的正则表达式结果。
and run that for each pair of match groups in your original regex results.
这篇关于正则表达式c#模式匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!