Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Sorry, I know this has likely been asked before but I just can't get it to work in my use case.

Need: In the below I need to extract the information between 245 and 250-03 (in bold).

Quote:
100-01/$1 郑择魁; 245-02/$1 《阿Q正传》的思想和艺术 / 郑择魁; 250-03/$1 第1版; 260-04/$1 杭洲 : 浙江人民出版社 : 浙江省新華書店发行, 1978.; 600-05/$1 鲁迅, 1881-1936. 阿Q正传


Problem: The end of the string (250 above) can be any 3 digits followed by a dash and 2 digits. So whenever I try \d\d\d-\d\d it grabs the final sequence of that pattern (881-19 in the example above)

What I have tried:

works in this particular example, but only because of the -03. Others do not.
245\-\d\d.*\d\d\d\-03


The below was where I got to but it has the problem listed above.
245\-\d\d.*\d\d\d\-\d\d
Posted
Updated 27-Jul-23 9:01am

1 solution

Try this pattern: 245\-\d{2}\/\$\d{1}(.*?)\d{3}\-\d{2}\/\$\d{1}

Example: regex101: build, test, and debug regex[^]
 
Share this answer
 
Comments
tas_666 1-Aug-23 23:15pm    
Hey Maciej, that's amazing. It's almost exactly what I want. Not sure if this should be a new question, but should this just give me the data between the numbers, or include the numbers? It's giving me the following, and I'd prefer not the bit at the end.
245-02/$1 《阿Q正传》的思想和艺术 / 郑择魁; 250-03
Maciej Los 2-Aug-23 15:17pm    
I haven't teested it on Oracle database...
As you can see, there's a Match#1 and Group#1. Group#1 is what you're looking for.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900