- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Replace '*' with '^' with Java Regular Expressions
To replace *' with '^' using Java Regular Expressions, we need to use the replaceAll() method. The replaceAll() method returns a String replacing all the character sequence matching the regular expression and String after replacement.
Declaration − The java.lang.String.replaceAll() method is declared as follows −
public String replaceAll(String regex, String replaced)
Let us see a program to replace '*' with '^' using Java Regular Expressions −
Example
public class Example { public static void main( String args[] ) { String str = new String("H*e*l*l*o"); System.out.println( "Initial String : "+ str); // replacing '*' with '^' str = str.replaceAll( "\*", "^" ); System.out.println( "The String after substitution : "+str ); } }
Output
Initial String : H*e*l*l*o The String after substitution : H^e^l^l^o
- Related Articles
- Search and Replace with Java regular expressions
- Replace one string with another string with Java Regular Expressions
- Replace all words with another string with Java Regular Expressions
- Validate Phone with Java Regular Expressions
- Validate city and state with Java Regular Expressions
- Validate the ZIP code with Java Regular expressions
- Working with Matcher.start() method in Java Regular Expressions
- Working with Matcher.end() method in Java Regular Expressions
- Working with simple groups in Java Regular Expressions
- Validate the first name and last name with Java Regular Expressions
- Looping over matches with JavaScript regular expressions
- How to use regular expressions with TestNG?
- Java Regular Expressions Tutorial
- Which package is used for pattern matching with regular expressions in java?
- Java regular expressions sample examples

Advertisements