2016-08-01 16 views

Antwort

1

Sie benötigen die regex wie:. (?<!&amp);Demo and Exaplaination

Bedeutung von regex: Finden Sie die ; die von & amp Voranstellung ist

Codebeispiel:

Pattern pattern = Pattern.compile("(?<!&amp);"); 
Matcher matcher = pattern.matcher("; abd &amp; this is what ;"); 
while(matcher.find()){ 
    System.out.println("find start position "+matcher.start() +" find end position "+matcher.end()+" find for "+ matcher.group(0)); 
} 

O/P

finden Position 0 find Endposition 1 Fund starten;

Startposition 25 finden Endposition 26 finden für;

+0

Das hat funktioniert; Tausend Dank. Sehen Sie es in Aktion unter http://ideone.com/Ml2lF6. – anthos

0

Ich glaube, Sie suchen einen regulären Ausdruck wie folgt aus:

^(&?!.).; * $

String line = "&abc\;"; 

Pattern r = Pattern.compile("^(?!.*&).*;.*$"); 
Matcher m = r.matcher(line); 
if (m.find()) 
System.out.println("Match found"); 
+0

Das hat nicht funktioniert; Siehe http://ideone.com/Ml2lF6 für die Geige wie ich es versucht habe. – anthos