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.
Related
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
How would I check in java if a string entered match the required format of aa/dddd where a represents a lower or upper-case letter and d represents a number
A simple regex to use: ^[A-Za-z]{2}/[0-9]{4}$
String regex = "^[A-Za-z]{2}/[0-9]{4}$";
String test = "ab/1232";
if (test.matches(regex)) {
// my regex matches
}
try this,
String str="aF/1234";
if(str.matches("[a-zA-Z]{2}/\\d{4}"))
System.out.println("Match");
I believe
String.matches("[A-Za-z]{2}/\\d{4}")
or
String.matches("[A-Za-z]{2}/[0-9]{4}")
would work.
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 am having a lot of trouble solving this error. Please help. The error is with fxRates.
private HashMap.String.Long.fxRates = newHashMap<String.Long>(40);
You have to use , not .
private HashMap<String,Long> fxRates = new HashMap<String,Long>(40);
Please read some basic java tutorial before proceeding.
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/](.+)" ?
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/