Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Gaurav Singh
rexexp pattern to avoid certain words and replace space with underscore
0 Answer(s)      3 years and 9 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


Advertisement
View Answers

Related Tutorials/Questions & Answers:
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
Advertisements
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
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
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
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
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
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
avoid using the whole URL
avoid using the whole URL  How can I avoid using the whole URL
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
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
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
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
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
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
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
Remove Extra Space At End
Remove Extra Space At End  Remove Extra Space At End
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
How to avoid Java Code in JSP-Files?
How to avoid Java Code in JSP-Files?  How to avoid Java Code in JSP-Files
time and space complexity
time and space complexity  sort the data structures according to efficient time and space utilisation
pattern printing
pattern printing  
String doubt replace function
String doubt replace function  What is the output and why of below : String s1 = "Hello"; if(s1.replace('H','H')== "Hello") System.out.println("yes"); else System.out.println("No"); if(s1.replace("H", "H")== "Hello
Replace String in PHP - PHP
Replace String in PHP  What is the fastest way of replacing string in PHP Code?  Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/php/phpbasics/PHP-Array-Replace.html Thanks
like query and then update or replace
like query and then update or replace   In postgres i use like query to find the a specific word in a column for example in a column i have text... to replace or update "wmost" to "westernmost" in that text. is there a way to do
Technical words for Business Analyst
Technical words for Business Analyst  Please provide me the list of technical words that a business analyst can use while creating artifacts
java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Java heap space error. This error is coming while...: Java heap space where there is no more space available for the Java program... space. You can also increase the Java heap space using following parameters
 

 

 

DMCA.com