4

I noticed that there's a regular expression character for bell. I can't match though. I read what this character is on wikipedia, but I don't understand how to find it in a regex.

<input type="text" value="␇" />
<input type="text" value="\a" />

http://jsfiddle.net/umQq8/

1252748
  • 14,597
  • 32
  • 109
  • 229

3 Answers3

4

/␇/ to match , /\\a/ to match \a

http://jsfiddle.net/umQq8/1/

The wikipedia article is about the bell character but the character is U+2407 SYMBOL FOR BELL, not the bell character

In your JSFiddle, you are writing \a in HTML, but in HTML the backslash escapes are not interpreted in any special way. In Javascript, backslash is a meta-character but the sequence \a is unrecognized and it will be treated as literal backslash and a. If you want actual bel character in your form, you need to write actual bel character (kinda hard because it's invisible) or &#7; you can't because those are illegal.

Esailija
  • 138,174
  • 23
  • 272
  • 326
  • I don't think he's trying to match a literal `\a` but the actual bell character for which `\a` is a shorthand. – mart1n Aug 02 '13 at 14:25
  • @mart1n `\a` is literally just `\a` in html. There is no `\a` escape in javascript either. If you want your input to have actual bel character then you need to write actual bel character, or use `` – Esailija Aug 02 '13 at 14:27
  • `/\a/` will match `` ? – 1252748 Aug 02 '13 at 14:32
  • @thomas no, `\a` is unrecognized in Javascript. `/\u0007/` will match it though – Esailija Aug 02 '13 at 14:36
  • @thomas actually never mind, control characters are illegal as input values it seems – Esailija Aug 02 '13 at 14:39
2
str.match(/\u2407/) !== null //string contains ␇
MDEV
  • 10,730
  • 2
  • 33
  • 49
0

In your IF statement, you can search for either \a (you have that in there already and it returns true) or the \u2407 character, which matches the bell unicode character.

mart1n
  • 5,969
  • 5
  • 46
  • 83