And preg_ What is the same Java as replace?
•
Java
<?PHP
<?PHP $str = "word <a href=\"word\">word</word>word word"; $str = preg_replace("/word(?!([^<]+)?>)/i","repl",$str); echo $str; # repl <word word="word">repl</word> ?>
Source: http://pureform.wordpress.com/2008/01/04/matching-a-word-characters-outside-of-html-tags/
Unfortunately, my project needs a semantic library for Java only
//Thank you, Celso
Solution
Use string Replaceall() method:
class Test { public static void main(String[] args) { String str = "word <a href=\"word\">word</word>word word"; str = str.replaceAll("word(?!([^<]+)?>)","repl"); System.out.println(str); } }
I hope this will help
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码