File size: 1,419 Bytes
81c95f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5587703
81c95f5
 
 
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import re
import json
from pathlib import Path

def parse_regex_file(file_path: str):
    """
    Parser robusto para o formato:
    buscar por / bus por
    PATTERN
    substituir por / sub por
    REPLACEMENT
    """
    content = Path(file_path).read_text(encoding="utf-8")
    
    # Dividir por blocos de "buscar por"
    blocks = re.split(r'(?i)bus(?:car)?\spor:?\s*', content)
    
    regex_pairs = []
    
    for block in blocks:
        if not block.strip():
            continue
            
        # Tentar separar pattern de replacement usando "substituir por" ou "sub por"
        parts = re.split(r'(?i)sub(?:stituir)?\spor:?\s*', block)
        
        if len(parts) >= 2:
            pattern = parts[0].strip()
            replacement = parts[1].strip()
            
            # Limpar comentários ou excesso de quebras de linha se necessário
            # (Manter o essencial para o Smali)
            if pattern and replacement:
                regex_pairs.append({
                    "search": pattern,
                    "replace": replacement
                })
                
    return regex_pairs

if __name__ == "__main__":
    pairs = parse_regex_file("regex_anuncios.txt")
    with open("regex_config.json", "w", encoding="utf-8") as f:
        json.dump(pairs, f, indent=4, ensure_ascii=False)
    print(f"Sucesso: {len(pairs)} pares de Regex extraídos para regex_config.json")