2

I would like to to create a regular expression in elisp (in the standard 'read' form) to match extended ASCII chars the same as PCRE does:

^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$

So, I'm currently сonfused about \x7f-\xff. Is there a way to set a range using something like \xhh?

  • I think the answer depends on whether you're matching against unibyte or multibyte strings. Do you think À (which is undefined in ASCII, 0xC0 in latin-1 and Unicode, but encoded as 0xC380 in UTF-8) falls into the range 0x7F-0xFF? – npostavs Apr 14 at 15:34
  • I think so. At least PCRE matched À as a char in 0x7F-0xFF range. I need the same behavior for standard Elisp regular expression. – serghei Apr 14 at 16:13
  • And as I can see À is defined in ASCII: ascii-code.com. 0xC0 is between 0x7F and 0xFF – serghei Apr 14 at 16:19
1

You can use -ÿ instead of \x7f-\xff. That first character, which StackExchange prints as a space, is DEL, which has codepoint 127 (decimal), #o177 (octal), and #x7f (hexadecimal).

That is, you can just insert the characters themselves in the regexp pattern.

One way to input such characters is to use C-x 8 RET. To search for any char in the range \x7f through \xff you would type this at the C-M-s prompt (without the spaces):

[ C-x 8 RET # x 7 f - C-x 8 RET # x f f ]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.