admin管理员组

文章数量:1026989

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" />

/

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/umQq8/

Share Improve this question asked Aug 2, 2013 at 14:07 12527481252748 15.4k34 gold badges117 silver badges242 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

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

http://jsfiddle/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.

str.match(/\u2407/) !== null //string contains ␇

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.

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" />

/

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/umQq8/

Share Improve this question asked Aug 2, 2013 at 14:07 12527481252748 15.4k34 gold badges117 silver badges242 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

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

http://jsfiddle/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.

str.match(/\u2407/) !== null //string contains ␇

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.

本文标签: javascriptTarget a bell character with a regular expressionStack Overflow