|
| ||||||||||
| Tags: composing, data types, programming language, regular expression, string |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Regex - compose a string
I'm working out on the regex and I'm at an impasse. I want to test if a string is composed as figure + - / *. So I created the following regex: Code: Public boolean isSentenceCorrect(String sentenceToTest)
{
pt = Pattern.compiles("\\d ");
= pt mter.mter(sentenceToTest);
mt = mter.games();
return correspondence;
} |
|
#2
| |||
| |||
| Re: Regex - compose a string
Hello, The "\ d" represents only the numbers. This will therefore lack the operators. I have an pattern with me, this should work fine. Just have a look at it. Code: pat.compiles("[\\d +-*/]") |
|
#3
| |||
| |||
| Re: Regex - compose a string
Hello, Code: pat.compiles("[\\d +-*/]") Code: Pat.compiles("[\\d\\+\\-\\*/]") |
|
#4
| |||
| |||
| Re: Regex - compose a string
Hello, Thanks for that it worked. I preferred to black and white and therefore the expression works fine as well, this was a perfect answer for that. But I have litter more problem with the following one, if you have any answer for this it would be great Code: Pat.compiles("[0-9+-*/]"); |
|
#5
| |||
| |||
| Re: Regex - compose a string
Hello, I have a code with me, just check out it this is the one you are looking for. Code: Public boolean isTwoOperatorSequence(String sentenceToTest)
{
String sg[] = {"+","-","/","*"};
int NBEL = sg.length;
int i = 0;
mt = false;
System.out.System.out.println(correspondence);
while(! mt & & i <NBEL)
{
String opt = sg[i];
String regex = "["opt + +"+]|["opt + +"-]|["opt + +"*]|["opt + +"/]";
System.out.System.out.println(regex);
pat = Pattern.compiles(regex);
= pat mter.mter(sentenceToTest);
mt = mter.find();
i + +;
}
return correspondence;
} |
|
#6
| |||
| |||
| Re: Regex - compose a string
Hello, I think you should try the following one this much smaller and much faster that I have seen so far. You can give it a try. Code: Public boolean twoseq(String sentest) {
return sentest.games("["+ Pattern.quote("+-*/")+"]+");
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Regex - compose a string" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem in retrieving string with Regex | Aaliya Seth | Software Development | 5 | 11-02-2010 04:53 AM |
| Regex string with quotes | Gunner 1 | Software Development | 5 | 07-02-2010 05:03 AM |
| Problem with Regex in returning string | Ash maker | Software Development | 5 | 05-02-2010 02:37 AM |
| Regex replace an integer with string | New ID | Software Development | 5 | 05-02-2010 12:35 AM |
| Regex strip out all non alpha Characters from a String | Chhaya | Software Development | 2 | 22-05-2009 06:51 PM |