Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Using the Captured Text of a Group within a Replacement Pattern

                         

In this section, you will learn how to use the captured text from the group of the text. This section illustrates you how to capture the string or text through the regular expression and it is also used through the regular expression. Here as you seen the regular expression of the code which has been used to capture each and every word one by one i.e. "(\\w+)" and another regular expression is "\"$1\"" i.e. used to replace with the same word covering by the "<>" characters.

"$1": This is the regular expression which determines the same word or characters where it is used for the specific purposes.

Here is the code of the program:

import java.util.regex.*;
import java.io.*;

public class CapturedText{
  public static void main(String[] argsthrows IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter string: ");
    String string = in.readLine();
    Pattern p = Pattern.compile("(\\w+)");
    Matcher m = p.matcher(string);
    String str = m.replaceAll("\"$1\"");
    System.out.println(str);
  }
}

Download this example.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Latest Searches:
struts radio button
Determining If a Year
jsp standard tags
Jtable Jbutton
how to create a frame
jpanel
awt jdbc
asterisk
if statement in a JSP
? С??? С??? С???
table grid
sample code using stru
MurachÑ??Ð?Ñ?Ð?Ð??Ñ??Ð
jpa spring transaction
convert ASCII to char
excel from java
struts formfile
rules
HWPF
Message Board JMB
Write a program that i
java inner class
connect SQL server in
javax.sql.* package of
Hibernate Set Attribut
data grid
program in java to ins
Read Cookies from Serv
getter setter methods
js tag
Flash Simple Motion Tw
vector in java
Mylyn
Photoshop Text Effects
Submit comments in dat
.sql conditions ibat
OutStream wrapper Clas
drop down list box
3DS MAX Effects Lights
heap memory
Photoshop Text Effects
metadata
Easy Java Tutorials
getStackTrace() to con
DES
is the jvm same for al
ะ�ะ�
jQuery to Select Multi
Photoshop Web Graphics
how to retrieve data f
VoIP Long Distance
source code for sendin
??â??â????â?????â?
upload
manage
server means
hibernate many to many
sample notepad source
Reports
java combo box
WebLogic Server Tools
Binary Tree JTree
h:inputtext tag in jsf
Photoshop Photo Retouc
Bubble sort with two n
calendar.set
passing values from js
optionsCollection
adding label and textb
options
compare two dates in j
i need simple date for
jbossconnectionpool
HQL
finding superscript in
Photoshop Web Layouts
dwr reverse ajax
ArrayList
reading file(java)
capture screen j2me
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.