• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regex for selecting pages  RSS feed

 
Sean Ross
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

Well, I'm stuck on a regular expression problem. I have a JTextField that is used to enter a range of pages. For example 11-21, 45-49. However I want to use Regex to pull this data as groups. So group one will be 11-21 and two will be 45-49. Lol I've been messing with this regex for about 3 hours and google searching all morning. However I just can't seem to get this to come together. This is what I have so far.



The issue is the comma and the space. I want to match it but exclude from group. I tried look arounds but cant seem to get this going. It matches one group but nothing more than this. As soon as I test with comma and space m.matches() returns false. Anything will be helpful. Thank you all.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your regex only has one group in it, so that is all it will find. I wouldn't try to fiddle and get more out of it, instead I would use Matcher#find() in a while loop to find all occurrences of the pattern in the input. Each loop should give you one group which represents one range of pages, which you process accordingly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!