I want to create a regular expression in java using standard libraries that will accommodate the following sentence:
12 of 128
Obviously the numbers can be anything though… From 1 digit to many
Also, I’m not sure how to accommodate the word “of” but I thought maybe something along the lines of:
[\d\sof\s\d]
This should work for you:
This will assume that you want to capture the full block of text as “one group”, and there can be one-or-more whitespace characters in between each (if only one space, you can change
\s+to just\s).If you want to capture the numbers separately, you can try: