• 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Regex for selecting pages

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.
Posts: 4179
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.
I'm so happy! And I wish to make this tiny ad happy too:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic