SHARE
TWEET

RegTest1

apuntesdejava Feb 4th, 2015 168 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.regex.*;
  2. import java.util.*;
  3. class RegTest1{
  4.         public static void main(String[] args){
  5.                 String expression=args[0],
  6.                        source=args[1];
  7.                 Pattern p=Pattern.compile(expression);
  8.                 Matcher m=p.matcher(source);
  9.                 List<Integer> posiciones=new ArrayList<>();
  10.                
  11.                 System.out.println("expression:" +m.pattern());
  12.                 System.out.println("source:" +expression);
  13.                 System.out.println(" index:012345678901234567890" );
  14.                 System.out.println("       0         1         2\n" );
  15.                 System.out.println("match positions:");
  16.                 while(m.find()){
  17.                         int pos=m.start();
  18.                         System.out.print(pos+" ");
  19.                         posiciones.add(pos);
  20.                 }
  21.                 System.out.println("\n\nCon marcas:");
  22.                 m.reset(); //reinicio la búsqueda para mostrar las marcas
  23.                 System.out.println("source:" +source);
  24.                 System.out.println(" index:012345678901234567890" );
  25.                 System.out.print("       ");
  26.                 for(int i=0;i<source.length();i++)
  27.                         System.out.print(posiciones.indexOf(i)>=0?'*':' ');
  28.  
  29.                                
  30.  
  31.                
  32.         }
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top