Here you can find the source of removeTags(String string)
,
...
Parameter | Description |
---|---|
string | Target String. |
public static String removeTags(String string)
//package com.java2s; /**//from www . ja v a2s . c o m * Copyright (C) 2012 Aleksi Postari (@kulttuuri, aleksi@postari.net) * License type: MIT (http://en.wikipedia.org/wiki/MIT_License) * This code is part of project Vaadin Irkkia. * License in short: You can use this code as you wish, but please keep this license information intach or credit the original author in redistributions. * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { /** * Removes tags from a given string and returns the parsed string.<br> * Example tags: <b>, </b>, <p>, <br/> ... * // TODO: TOO GREEDY. Make only check for HTML tags. * @param string Target String. * @return Returns the String where all the tags have been parsed. */ public static String removeTags(String string) { if (string == null || string.length() == 0) return string; Pattern REMOVE_TAGS = Pattern.compile("<.+?>"); Matcher m = REMOVE_TAGS.matcher(string); return m.replaceAll(""); } }