Bonjour,
Je parcours un fichier afin d'extraire puis modifier certaines des valeurs
voici l'exemple d'une ligne que je dois modifier :
<li><b><a href="#tss"><monTag:message bundle="legendes" key="menu.rech.a" /></b></a> : Option accessible en fonction du paramétrage. Accès... l'index du champ <monTag:message bundle="paramBase" key="test.0" />
Le code ci dessous fonctionne (Merci Uther), mais si j'ai plus de 2 occurrences, le seul moyen est-il de faire une récursive ?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
 static final Pattern PATTERN = Pattern.compile("<monTag:message .*? />");
    static Matcher matcher;
 
    {
        try {
            File file = new File("c:\\Temp\\file.txt");
            BufferedReader reader = new BufferedReader(new FileReader(file));
            String line = "", oldtext = "";
 
            int i = 0 ;
            while ((line = reader.readLine()) != null) {
 
               matcher = PATTERN.matcher(line);
               if(matcher.find()){
                   //transmettre la ligne:
                   System.out.println ("trouvé : " +i + " -- DEB ="+ matcher.start() + " -- FIN =" +matcher.end());
                   System.out.println (line);
 
                   if(matcher.find(matcher.end()));{
                   System.out.println ("trouvé : " +i + " -- DEB ="+ matcher.start() + " -- FIN =" +matcher.end());
                   System.out.println (line);}
 
                   i++;                   
               }