I am using the following regex - [a-zA-Z0-9]{9,18} which means I can use alphabets and numbers with minimum length as 9 and maximum length as 18.It should not take special characters.
It takes values like ADV0098890 etc. but it is also taking ADV0098890[] which is wrong.
I am trying to print alphabets from A to F using <c:forEach>
<c:set var="ctr" value="${optListSize}"></c:set> //optListSize is the size of an arraylist <c:forEach begin="65" end="${ctr}" varStatus="loop" step="1"> <c:out value="<%=String.fromCharCode(64+${ctr})%>"></c:out> </c:forEach>
I tried the above code but it gives an error. How to go about printing A, B, C, D... incrementally
I need to create a regexp, that will do the following:
a,a,a,a,c - matches c,a,a,a,a - matches a,a,a,a,a - doesn't match
I will be using it in Java. In the place of 'a', can be 'b' - they are equal. Also, in the place there can be any other character. This is what i have came up with:
It fails because it matches the 5 a's. I'm quite new to regexp, so I'm not aware of all the possibilities. It matches the 5 a's, because the first if fails, but the second does not. Maybe there is a simpler way to accomplish this? (Also why are the .* necessary in the middle?)
I would like to test whether the first word in a line is is a valid var name (e.g sequence of letters, digits and "_", it may not start with a digit, if "_" is the first char it must be followed by a letter). I tried this simple code:
String namePattern = "_[a-zA-Z0-9]+"; String text = "__c"; Pattern pattern = Pattern.compile(namePattern); Matcher matcher = pattern.matcher(text); "__c" is an illegal var name.
But it returns the string "_c", where it is supposed to return an empty matcher.
I am trying to write a regular expression for a text which has both String and number... like abc1234, xyz987, gh1052 etc. And the string usually contains 2 or 3 characters.
What I need is two Strings one containing the text (abc, xyz, gh etc) and other containing number (1234, 987, 1052, etc.). Have written the code below. but doesn't seem to work.
private static int getStrength(String pw) { int strength = 0; if(pw.length() >= 8){ strength++;
[Code] .....
This function doesn't seem to work for me. I believe the issue lies in the special character matching. It seems like it always returns true and adds to the strength. But I only want it to add to strength if at least one the following are in the password: *, -, _, ^, !, %
I have a table which contains list of regular expression and its corresponding value.I have to fetch those value and put it HASHMAP where regex as key.I have to compare the each key with the given string(input) and If matches I have to get the corresponding Value for the regex.
With the code below, I am trying to replace all regex matches for visa cards within a given text file.
My first test was with a text "new3.txt" exclusively containing the visa test card 4111111111111111. My objective was to replace the card with "xxxx-xxxx-xxxx-xxxx". This was successful.
However, when modifying the text file to include other characters and text before and after (ex: " qwerty 4111111111111111 adsf zxcv"), it gives mixed results. Although it successfully validates the match, it replaces the whole text in the file, rather than replacing solely the match.
When trying this search and replace with words (rather than a regex match), it does not have this behavior. What am I missing?
import java.io.*; import java.util.regex.*; public class BTest { //VISA Test private final static String PATTERN = "(?s).*4[0-9]{12}(?:[0-9]{3})?.*"; public static void main(String args[]) { try
Which of these is not a real differentiator for programming languages:
a) Object-oriented / Process-Oriented b) Interactive / Automated c) Interpreted / Compiled d) Strongly-Typed / Weakly-Typed e) All of the above f) B and C g) B and D
Almost all support OOP, Interactive/Automated, Interpreted/Compiled but not sure about Strongly typed/Weakly typed.
I have two ArrayLists and I want to compare them for common elements, and based on the result I want to update the first Arraylist to only have these elements. sort of like the opposite of RemoveAll() which removes elements in common and keep the ones that are unique. so far I thought of using for loop and .contains() in case it was fault,element not present, remove from list. but I was wondering in what other ways, perhaps APIs i can use to do that?
I need to create an algorithm that finds the common element(s) in all arrays that has a signature of public Comparable[] findCommonElements(Object[] collection) that has an efficiency of at most O(knlogn), uses a query array, and accepts as input a collection of arrays. I am aware my time would be better spent learning how to use array lists and hash sets, but I am supposed to use concepts already covered, and these have not been.
I feel like this code should work, but it is returning null for the array of common elements. Which means it obviously is not working correctly. I am also likely going to need implementing the sort algorithm, but I wanted to get the part of finding the common elements set first.
public class CommonElements2<T extends Comparable<T>> { Comparable[] tempArr; Comparable[] common; Comparable[] queryArray; /* sort algorithm goes here */ public Comparable[] findCommonElements(Object[] collections)
I have developed a web portal using jsp and struts 2. I have approximately 10 JSP pages which looks exactly the same and have two text areas and two hidden fields. All 10 pages are exactly the same except for hidden field value. Can't i have a single common jsp page. How can i achieve it. A sample page i am attaching...
I have a program in which I am prompting users for integer values to display in a JFrame. I call the method below to load an array with their input:
Java Code:
public String inputAssembly(){ if (!jtfInput.getText().matches("d")){ JOptionPane.showMessageDialog(null, "Input must be of integer value."); } if (jrbFar.isSelected()){ return jtfInput.getText() + jrbFar.getText();
[Code] ....
Regardless of the input, both messages display (invalid input / got it). I've tried debugging so I know that the values are getting entered and read correct, at least to my knowledge. It is a very simple regular expression, only checking to be sure an integer was entered.
I created filters for every column in my Jtable however, some of these columns have more than one word inside of them and my filters will only filter them based on the first word. For example if I had a first and last name in one column, it will filter the table if I enter the first name in my filter text field but it will not filter that same column if I only input the last name. What is a good regex expression to filter any word in any order?
when a new object is created in Java it follows the idiom:
Object obj = new Object(); where the Object() constructor matches the object type Object.
But what if it doesn't? I understand from the Oracle Docs on creating objects and polymorphism that the constructor must be in that object's class or one of its subclasses. However, suppose we wanted to declare a new stack. My first instinct would be:
Stack s1 = new Stack(); But I assume it's valid to do it this way, too:
Object s2 = new Stack(); // Is there a difference here? What are we really saying about s2? I'm guessing s2 is simply an empty stack, but only has access to the Object class methods? I'm not sure why someone would ever do this, but I want to solidify my understanding of the Java hierarchy. Are there really any circumstances where someone would use a subclass's constructor when creating a new object?