Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm having some problems with understanding how regular expressions work.
I am using Autolocation with Tasker on my android and have marked 2 types of locations with the patterns
[Safe] theNameOfTheSafePlace
and
[Danger] theNameOfTheDanger
I am trying to find out if the area I'm in is marked as safe or dangerous. I have tried using regex with the name
/[Safe/](.+)
but it doesn't recognize it.
What am I doing wrong and what would be the correct way to write this expression?
Thanks
You should be using backslashes \ to escape the [] not forward slashes.
Try:
\[safe\](.+)
Should be "\[Safe\](.+)" instead of "/[Safe/](.+)" ?
Related
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 3 years ago.
Improve this question
Can any one help me with the Java equivalent of this?
wordCountRDD.saveAsNewAPIHadoopFile(outputFile,classOf[Text],classOf[IntWritable],classOf[TextOutputFormat[Text,IntWritable]])
I tried below : but it give me error at TextOutputFormat<>(Text,IntWritable) ..
wordCountRDD.saveAsNewAPIHadoopFile(
output,
Text.class,
IntWritable.class,
TextOutputFormat<>(Text,IntWritable)
context.hadoopConfiguration());
Here:
TextOutputFormat<>(Text,IntWritable)
You have to pass the class instead:
TextOutputFormat.class
But note: the java type system doesn't allow you to express something like. TextOutputFormat<Text,IntWritable>.class! See here for why that is.
From that point of view, TextOutputFormat.class seems to be your only option.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I need a regex for patterns like
1) {-1,},
2) {-1,-2},
3) {,-2}
Please help me out.
try this,
String regex="\\{-?(\\d+)?,-?(\\d+)?},?";
String str="{-2,}";
System.out.println(str.matches(regex));
Try this,
^\{(\-\d+)?,(\-\d+)?\}$
Hope it works for you.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am trying below:
I am trying to process where condition of sql in java. How can I get column name in where condition as a string ?
Ex: String s = "Name_id>=11"
now I want to get "Name_id", as it is a column name and i want to do processing on it.
I know it can be done using regex but I am new to regex and don't know how to do it. can someone guide me??
help will be appreciated, thanks
You can try this
s = s.replaceAll("^(\\w+).+", "$1");
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a question about how to write a regex expression to get the key and value pairs from below string?
{"ReturnCode":"0","ErrorMsg":"success","EncryToken":"##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
Could someone help me learn on what this can be done?
Thanks very much.
This one should suit your needs:
"([^"]+)"\s*:\s*"([^"]+)"
The key is in the first group, the value in the second one.
Visualization by Debuggex
You can use Java JSON or the Google Gson to parse this JSON string ...
as illustrated here - http://answers.oreilly.com/topic/257-how-to-parse-json-in-java/
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have some specific task. We have String like "(()[]<>)" or something familiar with this.
A question in my interview qustion was how check either String is correct or incorrect.
For example: "()[]<>" - true, "([)" - false, "[(])" - false, "([<>])" - true.
Thank you guys very much!
You would need to use a stack to process this.
When you find a new opening parenthesis you would push onto the stack.
When you find a closing parenthesis, peek at the top element on the stack - and see if it matches. I.e. if you've just found a ")", was the last element on the stack a "("?
If it was, then pop that element of the stack. If it wasn't then you've got an "incorrect" String and you can stop processing any further.
Also, once you get to the end of the string, if there's anything left on the stack we know there's an non-terminated parenthesis.