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

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 5 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
time and space complexity
time and space complexity  sort the data structures according to efficient time and space utilisation
How to avoid Java Code in JSP-Files?
How to avoid Java Code in JSP-Files?  How to avoid Java Code in JSP-Files
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
pattern printing
pattern printing  
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
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
Program to Ignore Space and Enter ?!
Program to Ignore Space and Enter ?!  Hi, dear friend i wont to write program to enter many statements, if i use Space and Enter in the Run Time must be delete the space and ignore the Enter ..for example if i entered
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
Replace JSF Standard Error Message
Replace JSF Standard Error Message  How can we replace the JSF Standard Error Message
xmlname space in java
xmlname space in java  hi i want to write code like , i used setAttribute method for this. but its showing ERROR: 'Namespace for prefix 'company' has not been declared.' javax.xml.transform.TransformerException
remove space - Java Beginners
then please open that file with the filesteam object and just replace the text \n
Pattern Matching
Pattern Matching  hello, What operator performs pattern matching?   hii, The "LIKE" operator performs the pattern matching in SQL
Design pattern
Design pattern  explain factory pattern
avoid java code in jsp - Java Beginners
avoid java code in jsp  i want to show the arrayList values in a drop down box in struts the front page is jsp ,i am using struts1.3 ,i want to avoid java code in my jsp  Hi Friend, Please visit the following link
avoid duplicate values using struts - Struts
avoid duplicate values using struts  How to avoid the duplicate values in Struts?  IN action class you check before storeing itSee howFirst your storing data and database data both you check using any method and help
MySQL Replace
MySQL Replace       MySQL Replace function finds and replaces the occurrences of specified string...: REPLACE( String_Text, String_FROM, String_TO); where String_Text
Searching English words in a string
Searching English words in a string  My task is to find English words and separate them from a string with concatenated words..for example AhdgdjHOWAREgshshYOUshdhfh I need to find if there exists any English words.   
Pattern Making
Pattern Making  how to print this pattern in java? * * * * * * * * * * * * * * * * * It is just an example
Java heap space
Java heap space  I am using MyEclipse 8.6 for my web based project. The command may be... Ex: java -Xms32m -Xmx128m How can I increase java heap space??? and Where to use this command exactly?   Following are few
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
reverse words in a string(words seperated byone or more spaces)
reverse words in a string(words seperated byone or more spaces)  reverse words in a string(words separated by one or more spaces
how to space images in html code
how to space images in html code  how to space images in html code
space around/between my images
space around/between my images  How do I eliminate the space around/between my images
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
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
Java replace all non alphanumeric
Java replace all non alphanumeric  Hi, In Java how to replace all non alphanumeric characters with blank? Share me the best code for java replace...]" for finding all non alphanumeric characters and then replace it with required
 

 

 

DMCA.com