简体   繁体   中英

How to find substrings with a certain pattern within a string in Java

I'm using PDFBox to extract the contents of a PDF file. Following which I'll end up with one massive string.

Now, I need to extract all substrings in this string which match the pattern XX-XXXX (where the X can be a number or an alphabet) or XX YYYY (where X is a alphabet and Y is a number).

I tried ("([A-Z0-9]{2})-([A-Z0-9]{4})") to match the XX - XXXX pattern but it doesn't return me the expected values.

Please do a short study about Regular Expressions in Java. Once done have a look at the java.util.regex.Matcher. This helps a lot in finding text on the basis your regex. Below is a link that will help you a lot. http://tutorials.jenkov.com/java-regex/matcher.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM