Solved

java regex

Posted on 2013-11-19
6
938 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 28

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 36

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 36

Expert Comment

by:mccarl
ID: 39661424
I type too slowly! Sorry Doug, I didn't refresh the page before posting :)
0
Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

 
LVL 28

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 28

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

690 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