rexexp pattern to avoid certain words and replace space with underscore

rexexp pattern to avoid certain words and replace space with underscore

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 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
python replace newline with space
python replace newline with space  Hi, I want to replace newline character \n With space in python. How to replace newline with space in python? Thanks   Hi, Its easy in python. You can use the replace method
python replace newline with space
python replace newline with space  Hi, I want to replace newline character \n With space in python. How to replace newline with space in python? Thanks   Hi, Its easy in python. You can use the replace method
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
Replace
Replace   Hi, I have two text files in two diff locatons.The text file like below using java program 1)a.txt (adsbygoogle = window.adsbygoogle || []).push({}); 1 abc bangalore 2 def adfsdf 3
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
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
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
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
ModuleNotFoundError: No module named 'Underscore'
ModuleNotFoundError: No module named 'Underscore'  Hi, My Python... 'Underscore' How to remove the ModuleNotFoundError: No module named 'Underscore' error? Thanks   Hi, In your python environment you
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
Difference between translate and replace
of string. this work for entire word and pattern,. Translate replace the one...Difference between translate and replace   hiii, What is the difference between translate and replace?   hello,ADS_TO_REPLACE_1 Replace
avoid using the whole URL
avoid using the whole URL  How can I avoid using the whole URL
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
ModuleNotFoundError: No module named 'django-underscore'
ModuleNotFoundError: No module named 'django-underscore'  Hi, My... named 'django-underscore' How to remove the ModuleNotFoundError: No module named 'django-underscore' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django-underscore'
ModuleNotFoundError: No module named 'django-underscore'  Hi, My... named 'django-underscore' How to remove the ModuleNotFoundError: No module named 'django-underscore' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'XStatic-underscore'
ModuleNotFoundError: No module named 'XStatic-underscore'  Hi, My... named 'XStatic-underscore' How to remove the ModuleNotFoundError: No module named 'XStatic-underscore' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django-underscore'
ModuleNotFoundError: No module named 'django-underscore'  Hi, My... named 'django-underscore' How to remove the ModuleNotFoundError: No module named 'django-underscore' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'djungle-underscore'
ModuleNotFoundError: No module named 'djungle-underscore'  Hi, My... named 'djungle-underscore' How to remove the ModuleNotFoundError: No module named 'djungle-underscore' error? Thanks   Hi, In your
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
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 (adsbygoogle = window.adsbygoogle
ModuleNotFoundError: No module named 'avoid_disaster'
ModuleNotFoundError: No module named 'avoid_disaster'  Hi, My... named 'avoid_disaster' How to remove the ModuleNotFoundError: No module named 'avoid_disaster' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'avoid_disaster'
ModuleNotFoundError: No module named 'avoid_disaster'  Hi, My... named 'avoid_disaster' How to remove the ModuleNotFoundError: No module named 'avoid_disaster' error? Thanks   Hi, In your python
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
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
pattern printing
pattern printing 
ModuleNotFoundError: No module named 'django-babel-underscore'
ModuleNotFoundError: No module named 'django-babel-underscore'  Hi...: No module named 'django-babel-underscore' How to remove the ModuleNotFoundError: No module named 'django-babel-underscore' error? Thanks  
ModuleNotFoundError: No module named 'django-babel-underscore'
ModuleNotFoundError: No module named 'django-babel-underscore'  Hi...: No module named 'django-babel-underscore' How to remove the ModuleNotFoundError: No module named 'django-babel-underscore' error? Thanks  
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
Remove Extra Space At End
Remove Extra Space At End  Remove Extra Space At End
ModuleNotFoundError: No module named 'replace'
ModuleNotFoundError: No module named 'replace'  Hi, My Python... 'replace' How to remove the ModuleNotFoundError: No module named 'replace... to install padas library. You can install replace python with following command
Pattern Matching
Pattern Matching  hello, What operator performs pattern matching?   hii,ADS_TO_REPLACE_1 The "LIKE" operator performs the pattern matching in SQL
Design pattern
Design pattern  explain factory pattern
Maven Repository/Dependency: org.webjars.bower | underscore
Maven Repository/Dependency of Group ID org.webjars.bower and Artifact ID underscore. Latest version of org.webjars.bower:underscore dependencies. # Version Release Date 1
How to avoid Java Code in JSP-Files?
How to avoid Java Code in JSP-Files?  How to avoid Java Code in JSP-Files
Pattern Making
Pattern Making  how to print this pattern in java? * * * * * * * * * * * * * * * * * It is just an example
time and space complexity
time and space complexity  sort the data structures according to efficient time and space utilisation
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
ModuleNotFoundError: No module named 'space'
ModuleNotFoundError: No module named 'space'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'space' How to remove the ModuleNotFoundError: No module named 'space'
Maven Repository/Dependency: org.webjars.npm | underscore
Maven Repository/Dependency of Group ID org.webjars.npm and Artifact ID underscore. Latest version of org.webjars.npm:underscore dependencies. # Version Release Date 1 1.13.6
pattern program
pattern program  can some one plz help me to wright the logic for the following pattern abcdcba abc cba ab ba a a ab ba abc cba abcdcba
ModuleNotFoundError: No module named 'words'
ModuleNotFoundError: No module named 'words'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'words' How to remove the ModuleNotFoundError: No module named 'words'
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
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
Java pattern
Java pattern  Write a Java program that outputs the following pattern. 1 21 321 4321 54321 654321

Ads