Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need some basic regex help  RSS feed

 
Glenn Rueff
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess I must have forgotten a lot about regex since school because I cannot figure out what this program is doing. I understand everything up until what appears to be an extra iteration of the while loop.



When I run the program like this:
$ RegexTester "\d*" "12345"

My output is this:
Loop Number: 1
Start: 0
Group: '12345'
Loop Number: 2
Start: 5
Group: ''

When the entire string just got matched, why would it repeat the loop one more time and output a Start index that shouldn't be defined? Is it matching a null terminator? (Does Java use null terminators?)

Thanks in advance.
 
Stevi Deter
Ranch Hand
Posts: 265
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch. I suspect a bartender will be along presently to remind you to review the naming policy.

You might want to review the difference between "*" and "+" as quantifiers in your regex.

For example, do you get the result you were expecting when you call you program as:


A useful place to start is the Java Tutorial on Regex Quantifiers.
[ May 19, 2008: Message edited by: Stevi Deter ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"crosseyedalien", please check your private messages for an important administrative matter.
 
Glenn Rueff
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for taking a look at this, Stevi. The link you provided helps. (I don't know how, with all of my googling, I managed to miss that page.) I didn't realize that an empty string at the end of the text string would be considered significant. I'll have to read this stuff a little more thoroughly to understand what the reasoning is behind doing that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!