aspose file tools
The moose likes Java in General and the fly likes Regex help, replacing/espacing characters Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

Regex help, replacing/espacing characters

Sean Chang
Greenhorn

Joined: Feb 12, 2009
Posts: 12
Hey all,

I needed a little help writing a function in java that does the follow for escaping, I want to use regular expressions, I need the following characters to be replaced by a “~”

I posted it in beginners, but i think it is more fitting in this area.


The special characters are replaced as follows:

1. Newline, backspace, Control-M, carriage return, vertical tab characters are each replaced with "~"

2. Double quotes (") are replaced with single quotes (')

3. Then single quotes are escaped by inserting a backslash before each one.

Can someone give me a hand writing this? I don’t know regular expressions so it’s difficult for me to get going on this.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56179
    
  13

Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place. Please read this for more information.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regex help, replacing/espacing characters
 
Similar Threads
how to read a file in a string
replace method for String
Escaping special characters regex/function help
Can you simulate String.replace(...) & String.contains(...)
Changing spelling 'or' to 'our'