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 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号