I would like to ask the java regular expression in Matcher & Pattern
my code is
Pattern TR = Pattern.compile("\\\\[\+"\\\\]T\\\\[MR\\\\]");
I'm looking for the rgx for
+TR
"TR
+TM
"TM
There is something wrong on my regular expression. Could someone please point out ? Thank you so much
Just the below would be enough for your case.
Pattern TR = Pattern.compile("[+\"]T[MR]");
[+\"]
- Character class which matches double quotes or +
symbol.
[MR]
- Matches M
or R
character.
\"
- Matches the literal double quotes.
Example:
String[] s = {"+TR","\"TR","+TM","\"TM"};
for (String i:s)
{
System.out.println(i.matches("[+\"]T[MR]"));
}
Output:
true
true
true
true
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments