• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regex for selecting pages

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Everybody's invited. Even this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic