dqzlqfqeh845799833 2012-09-20 20:22 采纳率: 0%
浏览 89
已采纳

匹配以9位开头并可能以字符串结尾的字符串

I am basically trying to match a 10 character ISBN, so far I am able to match any string that is 10 characters long but it is not accurate at identifying the string as an ISBN

A 10 character long isbn can have 9 starting digits and end with a letter or have 10-digits, e.g.

0273737025

027373702X

If the final character is a letter it will always be X

what I have so far

[a-zA-Z0-9]{10,10}

this regex will be able to extract an isbn from a string like

"asjdh - asd a -  dsa- 0273737025"  = 0273737025

but will also extract anything else that is 10 or more characters long

"asjdh - asd a -  dsa- myveryearly"  = myveryearl

Is there a regular expression that can meet these requirements?

  • 写回答

3条回答 默认 最新

  • douhu3424 2012-09-20 20:25
    关注
    \d{9}(?:\d|X)
    

    This is 9 digits followed by either a digit or 'X'.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下