Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: replacing special characters in file

by polypompholyx (Chaplain)
on Aug 05, 2005 at 10:38 UTC ( #481172=note: print w/replies, xml ) Need Help??

in reply to replacing special characters in file

It depends on exactly what you want to do, but if you just want to strip out certain characters, you can do:

s/[^\w]//g; # strip everything but 'word' characters

s/[^[:ascii:]]//g; # strip everything but ASCII characters

If you want to specifically substitute certain character (sequences), you can do this using hex escapes in the regex, if you can't type them directly in your text editor:

s/\x{00A1}\x{00DC}/st/g; # replace upside-down-bang capital-u-umlaut with 'st'.

You can look up the (Unicode) hex values for capital-u-umlaut and friends in Unibook.

Bear in mind that the text you are editing may not be encoded in Unicode, and that even if it is, some characters may display differently in a terminal (particularly a DOS box) compared to how they will in a text file. Welcome to the inconsistent mess of character encoding standards.

Replies are listed 'Best First'.
Re^2: replacing special characters in file
by joemaniaci (Sexton) on Jun 01, 2012 at 18:08 UTC

    I have no idea if perlmonks prefers replying to the original thread or starting a new one if a certain amount of time has passed since the last reply, but I guess I'll find out soon enough. I too had odd characters like and , that were removed flawlessly, thanks to...


    ... but it also removed any * in the file as well, which is an ascii value. Any reason why?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://481172]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2018-02-22 03:54 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (288 votes). Check out past polls.