I am working on Windows Environment, I want to trim all non-Ascii characters and want only ascii range characters,numbers and symbols.Please help

My Input Was :

This is a simple text just for test purpose only ascii text 12345678910-=[];'#/.,-! " £ $ % ^ & * ( ) _ + { }~@:<>?|–

Now I am using JSON to decode my input data which decodes it as follows:

This is a simple text just for test purpose only ascii text12345678910-=[];\'#/.,\\-!\"\u00A3$%^&*()_+{}~@:<>?| \u2013

Now I am sending this decoded data to my Program to replace this unicode(utf-8) and other non-ascii characters with space/or some printable characters(I mean i want to print only ascii range characters) So, I tried all of the following in perl.

use strict; use warnings; use JSON; use LWP::UserAgent; use utf8; #Due to some security reasons I am not mentioning the url,hope u under +stand my $ResRef = sendHTTPRequest($someurlRequest); my $string = $ResRef->decoded_content;#I used json decode to decode co +ntent my $string = transalte_replace($string); sub transalte_replace { my $string = shift; for($string) { s/\\u[0-9]+/1-/g; s/\\u[a-zA-Z0-9\+]*/2-/g; s/\\x\{[a-zA-Z0-9]*\}/3-/g; s/[^\p{ASCII}]/-/g; s/[^\u0000-\u007F]+/replace1/g; s/[^\x00-\x7F]+/rep/g; s/[^\p{ASCII}]/-/g; s/[^A-Za-z0-9\.,\?'""!@#\$%\^&\*\(\)-_=\+;:\<\>\/\\\|\}\{\[\]`\~ +]+/y/g; #s/[£]//g; s/[^\x20-\x7E]+/replace3/g; #s/\\u[0-9]+/2-/g; #s/\\x[a-z0-9]+/3-/g; #s/[^\x00-\x7F]/4-/g; } }

The output still is:

"This is a simple text just for test purpose only ascii text12345678910-=[];'#/.,\-!\"\x{a3}\$%^&*()_+{}~\@:?|\x{2013}";


In reply to Regex to trim non Ascii characters by Yllar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.