Alphanumeric And Pipe Delimiter Regular Expression Validation

Sep 4, 2014

I have a header in file like below:
 
EMP_ID|EMP_NAME|DEPARTMENT|SALARY|ACTIVE1
 
passed to a string

String test = "EMP_ID|EMP_NAME|DEPARTMENT|SALARY|ACTIVE1";
 
I have to check if the header has only alphanumeric and pipedelimiter is allowed.

Other than these i need to raise an error.

View Replies


ADVERTISEMENT

How To Check Regular Expression

Aug 25, 2014

I have to match pattern like 76XYYXXXX mean x can be 4or 5 and Y can be 6 or 7. All x and y should be same .i.e. 764664444

View Replies View Related

Simple Regular Expression

Jan 17, 2014

I am currently enrolled in my first Java class. I have taken C# in the past so I've messed with some regular expressions, but I am having trouble finding a good website for Java. Is the syntax the same?I want to create a regular expression to only allow the following characters: c C f F [and any 1-3 digit number].

View Replies View Related

How To Use Regular Expression Using Pattern

Mar 16, 2015

I have a string "We have 7 tutorials for Java, 2 tutorials for Javascript and 1 tutorial for Oracle" I need to replace the numbers based on the below condition.
 
if more then 5, replace with many
if less then 5, replace with a few
if it is 1, replace with "only one"
 
below is my code, I am missing the equating part to replace the numbers

private static String REGEX="(d+)";
  private static String INPUT="We have 7 tutorials for Java, 2 tutorials for Javascript and 1 tutorial for Oracle";
  //String pattern= "(.*)(d+)(.*)";
  private static String REPLACE = "replace with many";
  public static void main(String[] args) {
  // Create a Pattern object

[Code]...

View Replies View Related

Java String Regular Expression

Apr 17, 2014

I have written below regex for two lines.

String LN1Pattern = "^((?=.{1,35}$)(/([A-Z]{1,5})(|(//[a-zA-Z0-9]+))))$";
System.out.println("/ABC//FGhiJkl012345".matches(LN1Pattern));
 
String LN2Pattern = "^(|((s+(//[a-zA-Z0-9]{1,33})){1,2}))$";
System.out.println("".matches(LN2Pattern));

s+ is a newline character.

But when I combines both as below, its not giving me expected result.

^(((?=.{1,35}$)(/([A-Z]{1,5})(|(//[a-zA-Z0-9]+))))(|((s+(//[a-zA-Z0-9]{1,33})){1,2})))$

For string "/ABC//FGhiJkl012345

//abCD01EF02" - returns False. Expected is True

I think there is some problem in lookahead placed.

View Replies View Related

Performing Regular Expression - Valid Last Name

Feb 4, 2015

I have some problems about performing regular expression. In the following code, the output as a result is being "valid last name". But in my opinion, it should be "invalid last name". Because "Doe" has not any space, apostroph or any hypen. Look at the regular expression statement: "[a-zA-Z]+([ '-][a-zA-Z]+)*"
 
package deneme; 
public class Deneme {
public static void main(String[] args) {
String lastName = "Mc-Something"; // Mc-Something 
if(!lastName.matches("[a-zA-Z]+([ '-][a-zA-Z]+)*"))
System.out.println("Invalid last name");
else
System.out.println("Valid last name");
}
}

I know that the asterisk qualifier means character(s) in any number.(Is this wrong?) So for "Mc-Something", 'M' corresponds to [a-zA-Z], 'c' corresponds to +, - corresponds to [ '-], 'S' corresponds to [a-zA-Z], "o" corresponds to +, and finally "mething" corresponds to *, doesn't they? But for "Doe", there is no any space, apostroph or hypen.

View Replies View Related

Regular Expression In Java Which Allow Only Numbers

Nov 28, 2013

I need a regular expression in java for phone number which that does not allow any character special character only numbers should be allowed.. My sample program is
 
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class c {
  public String removeOrReplacePhoneNumber(String input) {
  if (null == input)
  return input;

[Code] ....
 
but this is allowing characters like a,b,c..

View Replies View Related

I/O / Streams :: Parsing Logs Using Regular Expression

Dec 1, 2014

I am new to java coding. so, reading the log file using java code.

1) I wish to parse a file, and find a value for variable e.g. [StorageVersion].
2) After finding the value, it will be pushed to database.

Following is the code that i have written till now.

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.*;
import java.lang.*;
import java.util.*;
import java.util.regex.*;

[code]....

1) I don't know what regular expression can i use.
2) I want a line to check that preceding line should have //StorageVersion .
3) n then i will check any string between := K[' and '];. From above log file "'706146.0.22106932'" is the value that i am looking for.

View Replies View Related

How To Split A Text Looking For Values With Regular Expression

Aug 6, 2014

I have to read a text looking for value related to certain variable. The variable are always DE plus identifier from 1 to 99 or DE plus identifier from 1 to 99 and SF plus identifier from 1 to 99. The value can be alphanumeric. How can I get these values? As a start point, I try to use split("DE") but I can get something that is wrong if there is "DE" inside the text that doesn't me interest. I look for scanner but it doesn't work. I guess that there is some way, maybe using regex but I am completely lost ( I have never used regedix before and I am in rush to fix this).

Basically, the text is similar to the below where DE means data element and sf sub field. Some data elements have sub fields while others don't. I guess that there is a way to split with something like DE+anyNumberFrom1To99 = theValueAimed in some array and DE+anyNumberFrom1To99+,+SF+anyNumberFrom1To99 = theValueAimed in other array.

DE 2, SF 1 = 00 SOME TEXT THAT DOESN'T INTEREST ME
DE 22, SF 1 = 0 SOME TEXT THAT DOESN'T INTEREST ME
DE 22, SF 4 = 1 SOME TEXT THAT DOESN'T INTEREST ME
DE 22, SF 5 = 0 SOME TEXT THAT DOESN'T INTEREST ME
DE 22, SF 6 = 11 SOME TEXT THAT DOESN'T INTEREST ME
DE 22, SF 7 = 90x SOME TEXT THAT DOESN'T INTEREST ME
DE 22, SF 7 = 12ab SOME TEXT THAT DOESN'T INTEREST ME
DE 99 = 1234 SOME TEXT THAT DOESN'T INTEREST ME

View Replies View Related

Regular Expression In Java For HTML Pages

Feb 18, 2014

I need to parse an html web page to extract specific information from the tags in Java. For example,

<b>Species </b> Strain </td>

I need to look for the Strain info (Strain is variable in length) in the page. The whole web page is stored as a huge string. I need a regular expression that can identify all the Species and retrieve their corresponding strain info. how to do this or can propose some clever string manipulation methods in Java.

View Replies View Related

Specific Regular Expression - Split A String

Mar 3, 2014

Regular expression which I want to use to split a string. The string could look similar to this:

"a = "Hello World" b = "Some other String" c = "test""

The String is read from a file where the file contents would be:

a = "Hello World" b = "Some other String" c = "test"

After splitting I would like to get the following array:

String[] splitString = new String[] {"a", "=", ""Hello World"", "b", "=", ""Some other String"", "c", "=", ""test""}

I know I could just write a simple text parser to go over the string character by character, but I would rather not do it to keep my code clean and simple. No need to reinvent the wheel.

However, I just cant seem to be able to find the right regular expression for this task. I know that a RE must exist because this can be solved by a finite automaton.

View Replies View Related

Validate IP Address With Java Regular Expression

Jan 23, 2015

I am trying to implement an example (Book* : Java SE 7 ..By S G Ganesh) for validating an IP address but it fails to validate a valid IP addresses. I found another example on the internet(**) and it works super fine, no problem at all. I edited the code (the one I got from internet) into the exact format like book and it still works super but i don't understand why the books' example doesn't work though both look exactly the same now ,further more, how can i compare String x and y for equality?

public class TestClass {
void validateIP(String ipStr) {
String one = "((25[0-5]|2[0-4]d|[01]?dd?)(.)){3}(25[0-5]|2[0-4]d|[01]?dd?)"; //copied from internet and edited
String two = "((25[0–5]|2[0–4]d|[01]?dd?)(.)){3}(25[0–5]|2[0–4]d|[01]?dd?)"; // copied from book
String x = "((25[0-5]|2[0-4]d|[01]?dd?)(.))";
String y ="((25[0–5]|2[0–4]d|[01]?dd?)(.))";

[Code] ....

View Replies View Related

Java Servlet :: String Regular Expression

Mar 7, 2014

Do not want to use loop and  Character.isLetter to validation string , not sure at how to using regular expression?

If I want  8 characters string length, the first 3 is letter, the remind character is number ...

^[a-z0-9_-]{8}$
^[a-zA-Z]{3} + [/d]{5} $  ??

View Replies View Related

Regular Expression Match For String Containing Multiple Braces

Jan 1, 2015

I need a pattern that matches Hello Smith (STL Terminal) (15.0).

View Replies View Related

Regular Expression To Find A Line Beginning With A Certain Character Using Java?

Jul 12, 2014

I have a text file that has the following lines:

the boy is smart
He is from Australia
** Highly important line
That's all

Now, I need a regular java expression that would match a line in this file that begins with the ** characters. That is, when I match the text with the regex, I should get only this line :

** Highly important line

How would I write this regex in java?

View Replies View Related

Client / Server Using PIPE Line?

Apr 20, 2015

I have a program using Pipe line to exchange the infomation in the Client-Server model. Can I separate out main function and then put into Server main and Client main?

//PipeEchoServer
public class PipedEchoServer extends Thread {
PipedInputStream readPipe;
PipedOutputStream writePipe;
PipedEchoServer(PipedInputStream readPipe, PipedOutputStream writePipe){
this.readPipe = readPipe;

[code]....

View Replies View Related

RegEx For Uppercase Alphanumeric

Apr 14, 2014

I am in need of regex for alphanumeric (uppercase only) values which will verify string of length 5below

ABCCD - False
AB12C - True
ABC12 - True
12ABC - True
12345 - False

If it contain any lowercase then it should result in false as well.

My regex ^[A-Z0-9]{5}$ is not working for above type of values.

View Replies View Related

Incrementing Alphanumeric String By One

Sep 5, 2009

I have an assignment where I need to increment an alphanumeric string by one. For example AAA123 + 1 = AAA124. I'm okay with incrementing alpha or incrementing numbers, but incrementing them all together is where I am stuck. Should I just convert the entire string to ascii and increment there?

View Replies View Related

Unable To Implement Alphanumeric Security Code

Apr 10, 2014

I have been trying to implement a alphanumeric security code in JAVA. Here are my specifications:

1) Numbers and letters
2) There is user input
3) In the format of NNN-LL-NNNN where N=Numbers and L=UPPERCASE letters
4) If it is incorrect print out INVALID CODE
5) If it is correct print out VALID CODE

Here is what I have produced so far...

import java.util.*;
import java.io.*;
//Class Declaration
class WorkingWithStrings
{
//Main Method
public static void main(String[] args)
{
//Takes input from user

[Code]...

I have taking the approach of invoking a separate method that will check the validity of the security code. However I am having an issue with creating a statement that checks if the middle two characters of the security code are capital letters. This could possibly tie in with my understanding of strings.

View Replies View Related

FILE Input Without Delimiter

Apr 28, 2014

This is my input from my text file: 1|John Jay Smith|1985-01-10|2010-05-10|2014-03-05|212-222-2233..So, I have to convert 1 to integer. Break John Smith into first name as John and Middle name as Jay Last name as Smith.If no middle name is given then first is John and Last is Smith . Read 1985-01-10 as a date value . 2010-05-10 as another date value which could be null. 2014-03-05 as another date value which could be null. and at last 212-222-2233 as phone number.

Scanner sc = new Scanner (inFile);
sc.nextLine();
while (sc.hasNext()){

String row= sc.nextLine();

I want to read this line of input and assign the value accordingly.

View Replies View Related

Replace Value Of Delimiter In String

Jan 8, 2014

How can I change the value of

String str = "1234|U||45|||"
into
String str = "1234|U| |45| | |"

View Replies View Related

Delimiter Function And Number Of Words In String

Apr 20, 2014

Working on my java skills. The is Delimiter function is suppose to return true if there is a delimiter in the string and false otherwise. The main is suppose to call this function and count the number of words in the string:

Here is what I came up with:

import java.util.*;
 public class NumberOfWordsInString {
public static void main (String[] args){
Scanner in= new Scanner (System.in);
String s;

[Code] ....

Somehow my method isn't being successfully called by my main and the following error msg was received:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:

length cannot be resolved or is not a field

The method isDelimiter(char) in the type NumberOfWordsInString is not applicable for the arguments (char[])

at javaimprovements.NumberOfWordsInString.main(Number OfWordsInString.java:10)

line 10:
char ch [] = new char [s.length];

and the main doesn't call the isDelimiter function

View Replies View Related

I/O / Streams :: Reading Up To The First Delimiter And Then Moving On To Next Line?

Mar 22, 2014

I have a text file that has contents as follows:

testing1,true,0,0.0,0,0.0,4.0,0.0,0.0,0.0,0.0
test2,true,0,0.0,0,0.0,4.0,0.0,0.0,0.0,0.0

I am trying to read only the first item in each list using a comma as a delimiter using the following code.

public String[] pList() {
ArrayList<String> names = new ArrayList<String>();
String word;
try {
String path = P_FOLDER + P_FILE;

[Code]....

View Replies View Related

Delimiter - Type In 5 Strings From Java Console And Print Them All Out

Feb 13, 2015

I am testing some stuff here is my code:

public static void main(String[] args) {
String[] a = new String[5];
//String input = JOptionPane.showInputDialog(null, "enter input");
Scanner scanner = new Scanner(System.in);

[Code] ....

I am trying to type in 5 strings from java console and print them all out. I am using a "/" as a delimiter. My problem is that it does not print any output after I type strings separated by "/" like this: hello/gea/cae/eaf/aer and press enter. It works if I use JOptionPane but from the console its not working. I want to use the console instead of JOptionPane for this one.

View Replies View Related

How To Split String When Delimiter Also Is In The String

Mar 25, 2015

I have the the string value similar to the one   which i have to split based on the delimited ","
String SampleString=" 'ab,c', 'xyz', lm,n,o  "
 
I know I can easily call split function which will eventually split the above string. But in my case the delimiter ","  , is also a part of the string. If I call the function SampleString.split(',') I will get the output as listed below
 
ab
c
xyz
lm
n
o
but the expected  output is
abc
xyz
lmno

View Replies View Related

N-sided Regular Polygon

May 8, 2013

I'm working on is to create a program to display an n-sided regular polygon and uses two buttons named +1 and -1 to increase or decrease the size of the polygon. Also enable the the user to increase or decrease the size by clicking the right or left mouse button and by pressing the UP and DOWN arrow keys. So, first off I'm just trying to figure out how to display an n-sided polygon. I have some of the other components started, but I'm just trying to focus on getting this to work.

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Polygon;

[code]....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved