How to use regular expressions to remove parentheses
How do I use regular expressions to remove brackets? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
Example: color: pink [10] size: s [5]
Remove [] and content:
Preg_replace ("/\ [. *\] /",', $str) 1
Effect after treatment: color: pink size: s
Tip: you can change [] to other symbols and apply them where needed.
Ps: let's take a look at extracting the contents in parentheses using regular expressions
For example, now we want to extract the word "China" in parentheses in the sentence "people's Republic of China" for short (China).
Import java.util.regex.Matcher;import java.util.regex.Pattern;public class Test {public static void main (String [] args) {String str = "people's Republic of China, abbreviated as (China)." ; Matcher mat = Pattern.compile ("?