• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help programming regular expressions

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have the following code snippet:

Pattern p = Pattern.compile("(C|c)arriage return to continue:");
Matcher matcher = p.matcher(screenText);
screenText = matcher.replaceAll("");

Please note the the screenText is a string.

Lets take the following scenario, where the screentext is as follows:

"abcdef
Carriage return to continue:

cdefgh
carriage return to continue:

lmnop"

From the above code snippet, the output will be:

"abcdef


cdefgh


lmnop"

The output that I expect is:

"abcdef
cdefgh
lmnop"

Note that the output that I'm expecting does not have blank lines.. I want to remove the blank lines as well as the "carriage return to continue:" string!

Can anyone help me in getting the output that I expect! Please... Please.. help me..

Regards,

Kamal
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At the end of the line you're removing, there's a special character that says "this is the end of this line." Does your regular expression match that character?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, please don't post the same question to more than one forum; see our explanation here. I've deleted the other copy of this thread from the "Applets" forum.
 
Kamal Hassan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I'm not sure of the special character you are talking about. However, if you are talking about ":" then yes, it is removed. If I have not understood your question please rephrase it for me! To be more clearer, "Carriage return to continue:" is just an example I have taken and it could be replaced by any other string. However that string is followed by a blank line! what i want is to match the string inclusive of the following blank line and replace it with nothing. By nothing I mean that the replacement should not even lead to a blank line! Please help me program this!

Regards,
Kamal
 
reply
    Bookmark Topic Watch Topic
  • New Topic