Home Answers Viewqa Java-Beginners rexexp pattern to avoid certain words and replace space with underscore

 
 


Gaurav Singh
rexexp pattern to avoid certain words and replace space with underscore
0 Answer(s)      2 years and 2 months ago
Posted in : Java Beginners

I have a text string like "On River Thames in eastern London" and i want to replace space between two capital words with underscore so that "River Thames" becomes as "River_Thames" for this i am using the following pattern: Pattern p = Pattern.compile("\p{Lu}\p{L}+(\s+\p{Lu}\p{L}+)+");

The problem with this pattern is that it also replaces the space between "On River" to "OnRiver" and after using the complete pattern on input string it becomes "OnRiver_Thames in eastern London".

I want the pattern not to recognize the "On" word so i get output like "On River_Thames in eastern London". to achieve this i am using following pattern but it doesn't seems to work. Pattern p = Pattern.compile("(^On&&\s)+\p{Lu}\p{L}+(\s+\p{Lu}\p{L}+)+");

can someone help me in solving this?

Thanks a lot in Advance...

Regards YJ

View Answers









Related Pages:
rexexp pattern to avoid certain words and replace space with underscore
rexexp pattern to avoid certain words and replace space with underscore ... to replace space between two capital words with underscore so that "River Thames... with this pattern is that it also replaces the space between "On River" to "OnRiver" and after
Underscore b/w consecutive capatalized words
Underscore b/w consecutive capatalized words  I have a text something like this "25km from N of Rio Negro" I want to add underscore between consecutive Capatalized words having space between them. Can some one give me
Count words in a string method?
to given pattern. In above example we are splitting st by pattern â?? â?? ie by space...Count words in a string method?  How do you Count words in a string...(" "); System.out.println("Number of words : "+arr.length); }catch(IOException e
Pattern
Pattern  1234321 123 321 12 21 1 1 please,give me this pattern...[]) { int space=-1,counter=4; for(int i=1;i<=4;i++) { if(i<=1...++) System.out.print(j); for(int j=1;j<=space;j
regexp_replace in update and replace query in postgres
. is there a way to avoid this problem. Can you send similar query using regexp_replace...regexp_replace in update and replace query in postgres  update message set data = replace (data, 'wmost','westernmost'); April 4, 2011 at 5:04 PM
Difference between translate and replace
. this work for entire word and pattern,. Translate replace the one charecte...Difference between translate and replace   hiii, What is the difference between translate and replace?   hello, Replace replace every
tO FIND UNIQUE WORDS IN A FILE USING HASHMAP
tO FIND UNIQUE WORDS IN A FILE USING HASHMAP  import java.util....]", " "); // replace any grammatical characters and split the String...() { // create a HashMap to store unique combination of words
replace special characters in html
replace special characters in html  How can i replace the special characters in HTML?   Special Character in HTML HTML has a long list...; Space = &nbsp; " = &quot
java script to replace words starting and ending with tild(~) symbol in a text area with the word highlighted yellow.
java script to replace words starting and ending with tild(~) symbol in a text... requirement we have to replace all the occurence of such words and replace with highlighted text. for example: The script should findout all the occurence of the words
underscore as character
underscore as character  how can i consider _ as a character instead of wildcard character? my problem is like this i have 20 records as follows manohar 1234455 manohar 453635 manohar 345454 manohar_1234455 now when i am
Arrange the sentences in alphabetical order of words Java
Arrange the sentences in alphabetical order of words In Java Program In this section, we are going to sort the order of words in all the specified sentences... '.' or '?' or '!' followed by a single space. We have used split() method to split
Strategy Pattern of HashCode Equality
Strategy Pattern of HashCode Equality     2005-05-18 The Java Specialists' Newsletter [Issue 109] - Strategy Pattern of HashCode Equality... Pattern and how Java works with dynamic proxies
remove space - Java Beginners
then please open that file with the filesteam object and just replace the text \n
JavaScript split string into words.
JavaScript split string into words.  How to split string into words... the whole str value. Str.split(" ")- it split the str by finding the space. That is split str into words. Str.split("")-it split str into character
Java: Example - Words to array
into words you can use the space " " as token.    ... Java: Example - Words to array This example shows how to convert words to an array. We will use StringTokenizer to achieve the this.  
Replace
Replace   Hi, I have two text files in two diff locatons.The text file like below using java program 1)a.txt 1 abc bangalore 2 def adfsdf 3 ghij asdfdsad 2)b.txt A B C Now i want output is like below
Programming - Replace method
Java: Programming - Replace method Change all occurrences in a string.... The predefined Java function replace may not be used for this -- you have to write it yourself. Example CallReturnsComments replace("yesterday", "yes
Breaking the String into Words
Breaking the String into Words     ... into words. The java.util.*; package provides you a simple method to breaking the string into separate words. This program takes a string from user and breaks
Java String : Replace All
Java String : Replace All This section defines how to replace all character with specified character without using system methods. Replace All method : You can replace all specific character in a given string with another character
Set Space Ratio and Alignment
the alignment to be justified, the space between the words can... Set Space Ratio and Alignment     ... are going to explain how we can set space ratio and how we can gives various
how to print a new line after a certain number of prints
how to print a new line after a certain number of prints  How do I make this program print the inputs the user gives 5 per line? So in other words I want the program to print 5 input numbers per line. this is my code so far
Replacing all the text of String using expression
to Replace certain part of the whole String using regular expression. For this we... into a pattern. Here 'k|K' means to replace all in place of character (k or K). String... Replaceall.java are described below:- Pattern p = Pattern.compile("(k|K)ava"
pattern
of different sizes. The size of each pattern is determined by the number of columns or rows. For example, a pattern of size 5 has 5 columns and 5 rows. Each pattern is made of character $ and a digit, which shows the size. The size must
Pattern
Pattern  How to print this pattern in Java please help me A AC ACE ACEG ACEGI The program should be right to left
ereg_replace() and eregi_replace().
ereg_replace() and eregi_replace().  What is the difference between eregreplace() and eregireplace()?   Hi friends, ereg_replace() is case sensitive like "Bharat"cannot be treated as "bharat"and eregi_replace
pattern
pattern  1 3 1 5 3 1 7 5 3 1 9 7 5 3   Here is a number pattern example. 1 3 1 5 3 1 7 5 3 1 9 7 5 3 1 class Pattern{ public static void main(String args[]){ for(int i=1;i<=9;i
Web Hosting Bandwidth/Space/Transfer
. But these two words though sound same but signify different meanings. The bandwidth... to provide Unlimited Bandwidth or unlimited space because these companies themselves have limited bandwidth and hard disk space
Retrieve a list of words from a website and show a word count plus a specified number of most frequently occurring words
_pattern).matcher(content); while(match.find()){ ++total_words...Retrieve a list of words from a website and show a word count plus a specified... "words" form the document, and one by one, store each word as a key into a Map<
The Prototype Pattern
The Prototype Pattern       The Prototype Pattern:  This pattern enables you to copy... customized as per the requirement. It copies the existing object to avoid so much
avoid using the whole URL
avoid using the whole URL  How can I avoid using the whole URL
Singleton Pattern
Singleton Pattern       Singleton Pattern:  The singleton design pattern deals with one... from a common place. There are various ways of achieving this pattern. For example
Visitor Design Pattern - Java Interview Questions
Visitor Design Pattern  Tell me, what is Visitor Design Pattern... for Visitor Design Pattern?  Visitor Design Pattern - Used to create external class, that act on data in other classes. In other words Visitor design
String replaceAll() Method
;  In this program you will learn how to replace all the words... with. After that we have applied replaceAll(); method to replace that word. This method will replace all the words in a string as shown in the output. The code
Count numbers of spaces and number of words from the input string
Count numbers of spaces and number of words from the input string Java In this section, you will learn how to count the number of spaces and words from... have created a condition that if any white space character is found throughout
Replace TEXT
Replace TEXT   I have two text files in two diff locatons.The text file like below using java program 1)a.txt 1 abc bangalore 2 def adfsdf 3 ghij asdfdsad 2)b.txt A B C Now i want output is like below
How to avoid Hotel Telephone Bills
How to avoid Hotel Telephone Bills          Vioce Over Internet or VOIP For Short... enables users within an office set up share a certain number of outside lines to make
Pattern,Matcher,Formatter and Scanner classes
Pattern,Matcher,Formatter and Scanner classes This section Describes : 1... to format or parse strings or streams. 2. Uses of the Pattern and Matcher classes... pattern can then be used to create a Matcher object that can match arbitrary
What is the difference between ereg_replace() and eregi_replace()?
What is the difference between ereg_replace() and eregi_replace()?  What is the difference between eregreplace() and eregireplace
replace character in php
replace character in php  PHP script that replace character
find and replace in java
find and replace in java  Need 'find and replace' function in Java to find special keyword in XMl such as @,#,!,%..and replace with their corresponding entities
Design Pattern
Design Pattern           Behavioral Patterns Behavioral patterns are those... be loosely coupled in order to avoid hard coding and dependencies.   Read
MySql find and replace string
MySql find and replace string  How to find and replace string or special characters in MySql & PHP?   Find and Replace String PHP $result = preg_replace('/\band\b/i', 'foo', $subject
How to avoid the Special characters? - JDBC
How to avoid the Special characters?  I have a form in jsp and if someone enters special character (like single quote ') in text field (ex L'orel...,   hi friend, To avoid special characters we have imposed some
java.lang.string.replace()
The example discuss about the replace() method of Java String Class in Java. Use of string.replace() method in Java For a example if you wants to replace certain characters from the given string with your ones...then you should use
Design Pattern
Design Pattern        ... coupled in order to avoid hard coding and dependencies.    Iterator Pattern Iterator pattern is the mechanism of accessing all the objects
time and space complexity
time and space complexity  sort the data structures according to efficient time and space utilisation
String replaceFirst() Method
;  In this program you will learn how to replace words in a text... that we have applied replaceFirst(); method to replace that word. This method will only replace the word at the first position as shown in the output
pattern printing
pattern printing  
Example - Replace word
Java: Example - Replace word Problem: Write a method to replaces all... a new String. The word "replace" is probably misleading. Also, the method...". Not what was intended. The solution is to know about "words" Simply finding