Check a regular expression with string in Java

Asked

Viewed 102 times

0

I need to check if a particular digit recovered from a regular expression is equal to my input field digit, I am using the code below but can’t do the check:

String digitoSenha = senha.substring(i, i + 1);
RegularExpression expressao = new RegularExpression(digitoSenha + " ou \\d|\\d ou " + digitoSenha);

In case it returns: 1 or d| d or 1

I have an element on the screen that getText() return "4 or 1", as if the result of the expression is inside the getText() ?

  • new RegularExpression does not exist natively in Java. Is it a class from your project? If it is could [Edit] ask the question and put its code as well? Anyway, for me it’s not very clear what you want. Is there any example of strings that you get and what exactly you need to check? If you’re just going to see if there’s a digit 1 or 4 in the string, I guess indexOf is easier than regex...

  • I import this lib: import org.apache.xmlbeans.impl.regex.Regularexpression;

  • I’m not sure I understand what you want to do if (expressao.matches(getText()) { etc... }? If you enter the if is because the text matches regex. Another detail: I never used this lib, but unless it has some feature that the native API (java.util.regex.Pattern) does not support - and you need to use this feature - I see no need to use a lib.

  • I managed to do through the code below:

  • for (int i = 0; i <= password.length() -1; i++) { String typeNow = password.substring(i, i + 1); Regularexpression expression = new Regularexpression(digitNew + " or d| d or " + digitsNew); int button = 0; for (int x = 0; x <= 5; x++) { knob = knob + 1; String toggle = driver . findElement(By.xpath("//[@id='frmKey']/fieldset/div[2]/div[1]/a[" + boot + "]")). gettext(); if (expression.Boxes(boot)) { driver.findElement(By.xpath("//[@id='frmKey']/fieldset/div[2]/div[1]/a[" + button + "]")). click(); break; } } ;

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.