Check for specific string format [closed] - java

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.

Related

Regular expression for negative values in flower brackets [closed]

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.

Get column name from where condition in java [closed]

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");

How to display a portion of a string at an index of a string array [closed]

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 string array
String[] albumnames;
now how to take a string from particular index position with limited number of charachters.
For example,
if, albumnames[position] have value "abcdefghijk"
then i want to take the first 5 characters only.
That is "abcde".
The substring method of String can be used to achieve this. Try
String s = albumnames[position].substring(0,5);
See substring docs
albumnames[position].substring(0,5);
you can see the methods in String class, like substring, indexof

How to create substring from string at specific fixed length [closed]

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 java String with more than 160 character, on that i want to create substring form that string for first 150 character.
I have google it for that but what i got is for make substring at special character.
Please show me possible way for do this..
String#substring(int beginIndex, int endIndex) is what you need.
String mySubString = myString.substring(0, 150);

Regex expression to get the number out of the string [closed]

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 string like follows
XXXX456
For example i sometimes get the string as
<ignore>456
I want to get the number from this string
Try this:
String s = "<ignore>456";
System.out.println(s.replaceAll("\\D", ""));
Try:
yourStr = yourStr.replaceAll("[^\\d]", "");
Try this:
"([0-9]+)$"
Will match any number that's at the end.
Pattern p = Pattern.compile("-?\\d+");
Matcher m = p.matcher("<ignore>456");
while (m.find()) {
System.out.println(m.group());
}

Categories