简体   繁体   中英

Java Regex punctuation numbers and letters after numbers

I have text that I want to parse, It contains punctuation words letters etc. So far I used:

[\d\s\;\:\.\,\)\(]

And it seemed to work perfectly for me until I noticed that it was also picking up the "th" at the end of dates. (eg. 16th February).

How could I modify my current regex to make it work. I tried playing around with the whole ^ = start of string and $ = end of string but could not figure it out.

[\\d\\s;:.,)(]

You shouldn't need to escape things like the colon and semi-colon, but you may need to double escape the d and s in java.

The TH may be getting picked up because of bugs elsewhere in the code.

Also, I can't give as good advice since you're not very clear on your project. However, if you're selecting punctuation to get rid of it, you might instead try selecting what you want to keep and then get rid of everything else.

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