Solved

java regex

Posted on 2013-11-19
6
917 Views
Last Modified: 2013-11-25
Hi,

I was going through below link

http://www.tutorialspoint.com/java/java_regular_expressions.htm

Does java java regular expresssion is part of new java release or is it there from long time.

why we use regular expression. What are advantages, disadvantages, practical uses, alternative ways to it.

please advise
Any links resources ideas highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
  • 3
  • 2
6 Comments
 
LVL 26

Accepted Solution

by:
dpearson earned 250 total points
ID: 39661414
Java regular expressions have been in the language since version 1.4 (a long time ago now).

You can see this for any Java class by looking in the docs:
http://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html

Has a line:

Since:
1.4

which shows when it was added to the Java language.

Regular expressions are used when matching patterns in strings.  That comes up a lot in programming - e.g. making sure that a phone number follows the pattern:

(nnn) nnn-nnnn

can be easily checked with a regular expression.

They are also very fast when doing operations like scanning a big document for a specific pattern (e.g. find the first place where "Thanks" occurs before "advance" in a web page).

Much faster than code you would write yourself to do this - by perhaps getting the first character of the page, see if it's a "T".  If not, get the next character etc.

So they are good things to learn and use.

Doug
0
 
LVL 35

Assisted Solution

by:mccarl
mccarl earned 250 total points
ID: 39661419
Does java java regular expresssion is part of new java release or is it there from long time
A quick read of the Javadoc for the java.util.regex package says that the package and the classes within have been available since Java v1.4

http://docs.oracle.com/javase/7/docs/api/java/util/regex/package-summary.html

why we use regular expression
To allow quite flexible and potentially complex matching operations on a sequence of characters. And can also be used to perform replacement of found matches and possibly capture and return some part(s) of the found match. And plenty of other uses, I'm sure.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39661424
I type too slowly! Sorry Doug, I didn't refresh the page before posting :)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 26

Expert Comment

by:dpearson
ID: 39661447
Haha - great minds think alike mccarl!

Doug
0
 
LVL 7

Author Comment

by:gudii9
ID: 39670090
They are also very fast when doing operations like scanning a big document for a specific pattern (e.g. find the first place where "Thanks" occurs before "advance" in a web page).

I have not understood this use case. what is the meaning of 'Thanks' occurs before "advance".

Please advise
0
 
LVL 26

Expert Comment

by:dpearson
ID: 39670870
I have not understood this use case. what is the meaning of 'Thanks' occurs before "advance".

It was just an example - searching for the word "Thanks" occurring somewhere in a document before the word "advance"

Thanks for helping.    // No match
Thanks in advance.    // Match - but notice how the words aren't next to each other

It's not that easy to write code to do this yourself.  But regular expressions handle it really well.

Doug
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now