如何使用正则表达式从文本中提取isbn 10/13数字 [英] how to extract isbn 10/13 number from text using regular expression

查看:353
本文介绍了如何使用正则表达式从文本中提取isbn 10/13数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从文本中提取isbn 10/13代码我试过2-3正则表达式,但没有一个工作可以帮助我解决我的问题。以下是我的实现,如果可能的话告诉我我的代码有什么问题。





  string  strRegex =  @  ISBN\x20(?=。{13 } $)\d {1,5}([ - ])\d {1,7} \1 \\\ {1,6} \1(\d | X)$; 
RegexOptions myRegexOptions = RegexOptions.None;
Regex myRegex = new 正则表达式(strRegex,myRegexOptions);
string strTargetString = @ 谢谢你获取WPF 4 Unleashed!Windows Presentation Foundation(WPF)是Microsoft创建Windows图形用户界面的首要技术,无论它们包括普通表单,以文档为中心的窗口,动画卡通,视频,沉浸式3D环境,还是以上所有内容。 WPF是一种比以往更容易创建各种应用程序的技术。 + \\ \\ n + @ ISBN-13:978-0-672-33119-0 + \ n + @ ISBN-10:0-672-33119-5 + \ n + @ 它也是Silverlight的基础,它将WPF技术扩展到Web上,并扩展到Windows手机等设备中。;

foreach (匹配myMatch myRegex.Matches(strTargetString))
{
if (myMatch.Success)
{
Console.WriteLine(myMatch.Groups [ 1 ]值);
}
}

解决方案

)\d {1,5}([ - ])\ d {1,7} \1\d {1,6} \1(\d | X)


;
RegexOptions myRegexOptions = RegexOptions.None;
Regex myRegex = new 正则表达式(strRegex,myRegexOptions);
string strTargetString = @ 感谢您选择WPF 4 Unleashed! Windows Presentation Foundation(WPF)是Microsoft创建Windows图形用户界面的首要技术,无论它们是由普通表单,以文档为中心的窗口,动画卡通,视频,沉浸式3D环境还是上述所有内容组成。 WPF是一种技术,可以比以往更轻松地创建广泛的应用程序。 + \ n + @ ISBN-13:978-0-672-33119-0 + \ n + @ ISBN-10:0 -672-33119-5 + \ n + @ 它也是Silverlight的基础,它将WPF技术扩展到Web上,并扩展到Windows手机等设备中。 ;

foreach (匹配myMatch myRegex.Matches(strTargetString))
{
if (myMatch.Success)
{
Console.WriteLine(myMatch.Groups [ 1 ]。缬氨酸ue);
}
}


看看这里: http://regexlib.com/Search.aspx?k=ISBN&AspxAutoDetectCookieSupport=1 [ ^ ]。在那里你会找到一个解决方案;)



在我看来这个正则表达式:

ISBN(-1( ?:( 0)| 3)):\x20 +((1)((2)(:(= {13}

??????。

hi, i need to extract the isbn 10/13 code from the text i tried 2-3 regular expression but none of them working could anyone help me to solve my problem. following is my implementation if possible tell me what is wrong with my code.


string strRegex = @"ISBN\x20(?=.{13}$)\d{1,5}([- ])\d{1,7}\1\d{1,6}\1(\d|X)$";
            RegexOptions myRegexOptions = RegexOptions.None;
            Regex myRegex = new Regex(strRegex, myRegexOptions);
            string strTargetString = @"Thank you for picking up WPF 4 Unleashed! Windows Presentation Foundation (WPF) is Microsoft’s premier technology for creating Windows graphical user interfaces, whether they consist of plain forms, document-centric windows, animated cartoons, videos, immersive 3D environments, or all of the above. WPF is a technology that makes it easier than ever to create a broad range of applications. " + "\n" + @"ISBN-13: 978-0-672-33119-0 " + "\n" + @"ISBN-10: 0-672-33119-5" + "\n" + @"It’s also the basis for Silverlight, which has extended WPF technology onto the Web and into devices such as Windows phones.";

            foreach (Match myMatch in myRegex.Matches(strTargetString))
            {
                if (myMatch.Success)
                {
                    Console.WriteLine(myMatch.Groups[1].Value);
                }
            }

解决方案

)\d{1,5}([- ])\d{1,7}\1\d{1,6}\1(\d|X)


"; RegexOptions myRegexOptions = RegexOptions.None; Regex myRegex = new Regex(strRegex, myRegexOptions); string strTargetString = @"Thank you for picking up WPF 4 Unleashed! Windows Presentation Foundation (WPF) is Microsoft’s premier technology for creating Windows graphical user interfaces, whether they consist of plain forms, document-centric windows, animated cartoons, videos, immersive 3D environments, or all of the above. WPF is a technology that makes it easier than ever to create a broad range of applications. " + "\n" + @"ISBN-13: 978-0-672-33119-0 " + "\n" + @"ISBN-10: 0-672-33119-5" + "\n" + @"It’s also the basis for Silverlight, which has extended WPF technology onto the Web and into devices such as Windows phones."; foreach (Match myMatch in myRegex.Matches(strTargetString)) { if (myMatch.Success) { Console.WriteLine(myMatch.Groups[1].Value); } }


Have a look here: http://regexlib.com/Search.aspx?k=ISBN&AspxAutoDetectCookieSupport=1[^]. There you'll find a solution ;)

In my opinion this regex:
ISBN(-1(?:(0)|3))?:?\x20+(?(1)(?(2)(?:(?=.{13}


这篇关于如何使用正则表达式从文本中提取isbn 10/13数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆