Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
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:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Programmer Certification (OCPJP)
Pattern Matching
Sudharsan Ashwin
Greenhorn
Posts: 18
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
package pack.generics; import java.util.regex.*; public class RegEx { public static void main(String [] args) { System.out.println("Next"); String regex ="(b-d)*"; String match = "b-db-db-d"; Pattern p1 = Pattern.compile(regex); Matcher m1 = p1.matcher(match); while(m1.find()) { System.out.print(m1.start() + " "); } }
I am getting output as "0 9", but the length of the
string
match is 9.
Can anyone explain?
Myself
Ankit Garg
Sheriff
Posts: 9708
43
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Since you've written
(b-d)*
, so there will be an empty match at the end of the string as
*
means 0 or more occurrences of something...
SCJP 6 | SCWCD 5 |
Javaranch SCJP FAQ
|
SCWCD Links
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3412
320
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Ankit is correct, so if you change it into (+ means one or more occurences)
String regex = "(b-d)+";
you will get:
0
or into:
String regex = "(b-d)";
you will get:
0 3 6
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Pattern matching problem
Extracting numbers from a String using regular expressions
Regex clarification
Regex Woes
Problem with Regex
More...