我有下面的字符串,我想提取医生的名字。我可以用什么正则表达式来实现这个目标?
$($('#menu-button-label').click(function() {
if($('#menu-button').is(':checked')) {
$('#menu-button-label').animate({marginTop: '0%'},500);
}
});
答案 0 :(得分:2)
(?<=:\s).*
此正则表达式将执行以下操作:
直播示例
https://regex101.com/r/oH4wK1/1
示例文字
Doctor : JOHN A. BROWN
返回匹配
[0] => JOHN A. BROWN
NODE EXPLANATION
----------------------------------------------------------------------
(?<= look behind to see if there is:
----------------------------------------------------------------------
: ':'
----------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
) end of look-behind
----------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
答案 1 :(得分:0)
正则表达可能有点矫枉过正。 相反,为什么不从原始字符串中取出一个子字符串。
Dim data As String = "Doctor : JOHN A. BROWN"
Dim name As String = data.Substring(data.IndexOf(":") + 2)
注意,做&#39; + 2&#39;在子字符串的起始索引上跳过&#39; &#39;出现在&#39;:&#39;。
之后答案 2 :(得分:0)
答案 3 :(得分:0)
How about:
^Doctor\s*:\s*(.*)
This will exclude the "Doctor :" field and match anything after the colon.