• 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

doubt on regex

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.util.regex.*;
class Regex2{
public static void main(String[] args){
Pattern p=Pattern.compile(args[0])
Matcher m=p.matcher(args[1]);
boolean b=false;
while(b=m.find()){
System.out.println(m.start()+m.group()+"");
}
}
}
and we give java Regex2 "\d\s\w" "12s 4w 33 1"


output for this is: 44 w 93

Can anyone explain me this. And i don't have much idea on this regex class also. can anyone provide clear explanation about this topic.
Thanks in Advance.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Funny enough that it actually outputs "83 1", because it looks for the following sequence :
\d A digit: [0-9]
\s A whitespace character: [ \t\n\x0B\f\r]
\w A word character: [a-zA-Z_0-9]

So 8th position, there is "3 1".

Or am I missing something ?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic