[英]Recognize roman numeral followed by '.', space and then capital letter. (RegEx)
Can someone please help me with this?有人可以帮我吗?
I'm trying to match roman numerals with a "."我正在尝试将罗马数字与“。”匹配。 at the end and then a space and a capital letter after the point.
在末尾,然后是一个空格和一个大写字母。 For example:
例如:
I. And here is a line. I. 这是一条线。
II.二、 And here is another line.
这是另一条线。
X. Here is again another line. X. 这里又是另一行。
So, the regex should match the "I. A"
, "II. A"
and "X. H"
.因此,正则表达式应该匹配
"I. A"
、 "II. A"
和"X. H"
。
I did this "^(XC|XL|L?X{0,3})(IX|IV|V?I{0,3}){1,4}\.\s[AZ]"
But the problem is that this RegEx is also matching with ". A"
and i don't want it.我做了这个
"^(XC|XL|L?X{0,3})(IX|IV|V?I{0,3}){1,4}\.\s[AZ]"
但问题是这个正则表达式也与". A"
匹配,我不想要它。
In resume it should have at least one roman numeral, followed by a "."
在简历中,它应该至少有一个罗马数字,后跟一个
"."
and then a space and a capital letter.然后是一个空格和一个大写字母。
You need a (?=[LXVI])
lookahead at the start that would require at least one Roman number letter at the start of the string:您需要在开头有一个
(?=[LXVI])
前瞻,在字符串的开头至少需要一个罗马数字字母:
^(?=[LXVI])(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})\.\s[A-Z]
# ^^^^^^^^^
See the regex demo .请参阅正则表达式演示。 Not sure why you used
{1,4}
, I suggest removing it.不知道你为什么使用
{1,4}
,我建议删除它。
Another workaround here would be to use a word boundary right after ^
:这里的另一个解决方法是在
^
之后使用单词边界:
^\b(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})\.\s[A-Z]
#^^
This would disallow a match where .
这将不允许匹配 where
.
appears at the start since \b
, required at the same position as the start of string, requires that the next char must be a word char (and here, it must be a Roman number).自
\b
以来出现在开头,需要与字符串开头相同的 position ,要求下一个字符必须是单词 char (这里,它必须是罗马数字)。
Regarding \.\s[AZ]
, you may enhance it you add +
or *
after \s
, and if you ever need to match it and exclude from a match, turn it into a positive lookahead, (?=\.\s+[AZ])
or (?=\.\s*[AZ])
.关于
\.\s[AZ]
,您可以在\s
之后添加+
或*
来增强它,如果您需要匹配它并从匹配中排除,请将其转换为积极的前瞻, (?=\.\s+[AZ])
或(?=\.\s*[AZ])
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.