Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I want to match a string containing slashes in Java. I have the following code:
String exclude = "some/class/in/package/*.class";
String className = "some/class/in/package/TheClass.class";
boolean value = className.matches(exclude);
System.out.println(value);
>false
Can anyone help me to fix this?
Valid class names must start with a letter so it could reasonably be
"some/class/in/package/[A-Za-z].*\\.class"
But then you probably ought to put in valid characters for the rest
"some/class/in/package/[A-Za-z][A-Za-z0-9_]*\\.class"
Nevermind, I had forgotten the '.' before '*'
String exclude = "some/class/in/package/.*.class";
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 days ago.
Improve this question
I have a CSV that I am trying to parse in a java program. Each value has double quotes around it. They are separated by comma(,). Value within quotes could have commas inside them- that needs to be ignored/escaped.
I need to split this string and parse out:
"Hello","Test","Hi, how are you?","State","Sorry,ABC!Team"
Result I want after split is array with following values. Use the right comma as separator.
Result:
Hello
Test
Hi, how are you?
State
Sorry,ABC!Team
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I'm trying to define a Constant with some pattern identifier to be able to replace it in large String constructs later, for example in a complex Querie.
private static String SUBSTITUTE_1 = "${substitute1}";
But when I do that, compiler complains about expecting a number next to the '{' char.
My question is: Is there a way to escape the special characters in the string?
private static String SUBSTITUTE_1 = "\$\{substitute1\}";
This does not work.
This is strange because if I define a String builder like so
private static String SUBSTITUTE_1 = new StringBuilder("${substitute1}").toString();
there no problem with the special characters.
Unless there is something really obvious that i'm missing this does not make sense.
Thanks in advance.
Apparently, Intellij's compiler detects that somewhere in the code I'm using the defined constant in a String.replaceAll() instruction and complains about its definition as "${x}" is not a valid Regex Expression.
Solution is change to String.replace().
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
For a string foo, and a regular expression REGEX, why doesn't this work:
foo.indexOf(foo.matches(REGEX) ? '<' : "--");
what is wrong with this ternary?
The two expressions of the ternary conditional have to be the same type (or implicitly convertible to a common type). '<' and "--" are respectively a char and a java.lang.String. One cannot be implicitly converted into the other.
To fix, use the more long-winded
foo.matches(REGEX) ? foo.indexOf('<') : foo.indexOf("--");
Two different overloads of indexOf are used here but since the return types are identical the ternary conditional is grammatically correct.
Try changing this '<' to "<"
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
Consider we have the following set of String:
String text="Geeraertsb,∗,1";
String text2="bla bla";
String text3="in terms of ";
I would like to get those strings that do not contain either of & and/or "*". so that means only `text2" is of interest.
however if I use:
if(!text.contains("*"))
{
//do something
}
if(!text3.contains("&"))
{
//do something
}
it does enter the if statement while it should not. Any idea why?
You're using different characters
∗ is not equal to *
You may want to check that you're using the same set of characters for you String objects and your conditions.
You can try like this:
Pattern mypat = Pattern.compile("[^a-z ]", Pattern.CASE_INSENSITIVE);
Matcher mat = mypat.matcher("Geeraertsb,∗,1");
boolean found = mat.find();
if (found)
{
//code
}
The above code uses the regex approach in which you try to check if your string contains anything apart from the alphabets.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
System.out.println("if(line.contains(\"<string key=\"concept:name\" value=\"LCSP\"/>\"\))");
I am getting an error. I want to print above statement as a string.
Can someone help me.
Remove the last backslash \ there is no need to escape )
System.out.println("if(line.contains(\"<string key=\"concept:name\" value=\"LCSP\"/>\"))");
DEMO1
Solution to the problem given in comment
String v11 = "John";
System.out.println("if(line.contains(\"<string key=\\\"concept:name\\\" value=\\\""+v11+"\\\"/>\"))");
OUTPUT
if(line.contains("<string key=\"concept:name\" value=\"John\"/>"))
DEMO2
Original
System.out.println("if(line.contains(\"<string key=\"concept:name\" value=\"LCSP\"/>\"**\**))");
**** is not required I have removed from Original
Changed:
System.out.println("if(line.contains(\"<string key=\"concept:name\" value=\"LCSP\"/>\"))");
String v11 = "John1";
System.out.println("if(line.contains(\"<string key=\\\"concept:name\\\" value=\\\""+v11+"\\\"/>\"))");
remove the last backlash and update the "LCSP" to v11 variable.
output:
if(line.contains("<string key=\"concept:name\" value=\"John1\"/>"))
no need to escape ')' at end of the line.
the changed statement is:
System.out.println("if(line.contains(\"<string key=\"concept:name\" value=\"LCSP\"/>\"))");