1

I would like help on building a regular expression to find ACII codes

So far I came up with this, http://jsfiddle.net/G7cab/

but as you'll notice I'm not capturing all the groups that match this expression.

I would appreciate some help Many thanks in advance.

just_a_dude
  • 2,745
  • 2
  • 26
  • 30

2 Answers2

3

Here's a shorter form for (what I understood you) wanted to do based on your fiddle:

var s = '' ^ hola tio, que tal estas? !'
          .replace(/(&#\d+;)/g,
             function(a){
              return String.fromCharCode(a.substr(2,a.length-3));
             }
           );
 alert(s); //=> ' ^ hola tio, que tal estas? !

So, the regular expression here is /(&#\d+;)/g

By the way, &[#num][name]; are called (numeric) html entities. The code here is only working for such entities (so, not for named html entities like © (©) etc.). If you want to do that (and within a browser), use the method from the elected answer in this SO question

Community
  • 1
  • 1
KooiInc
  • 119,216
  • 31
  • 141
  • 177
0

I guess you're trying to unescape HTML Entities. It was discussed on SO:

Unescape HTML entities in Javascript?

Community
  • 1
  • 1
Evgeny Shadchnev
  • 7,320
  • 4
  • 27
  • 30