Extract an ISBN with regex

后端 未结 7 1930
终归单人心
终归单人心 2021-01-14 01:01

I have an extremely long string that I want to parse for a numeric value that occurs after the substring \"ISBN\". However, this grouping of 13 digits can be arranged differ

7条回答
  •  粉色の甜心
    2021-01-14 01:27

    Do it in one step with a pattern recognizing everything, and optional dashes between digits. No need to fiddle with ISBN offset + substrings.

    ISBN(\d(-?\d){12})
    

    If you want the raw number, strip dashes from the first matched subgroup afterwards. I am not a Java guy so I won't show you code.

提交回复
热议问题