Perl Regular Expression cannot find fancy quotes "

I tried to find fancy quotes from a string using the following Perl regular expression, but it returns false.

$text = "NBN "a joint venture with Telstra"";

if ($text =~ m/"/)
{
  print "found";
}

I also tried using the \x93ascii code " " but still does not work. I'm stuck here.

Any help is appreciated.

Regards, Allen

+5
source share
3 answers

Depending on the encoding of the string you are trying to match, you may need to do different things. See Absolute Minimum. Every software developer should absolutely, be positively aware of Unicode and character sets (no excuses!) .

UTF-8, perl script - use encoding 'UTF-8'.

use utf8, , script UTF-8. , , , , , , :

use utf8;
use encoding 'UTF-8';

$text = "NBN "a joint venture with Telstra""; # Make sure to quote this string properly

if ($text =~ m/\N{U+201C}/) # " is the same as U+201C LEFT DOUBLE QUOTATION MARK
{
  print "found";
}
+3

. "Demoroniser" "" Perlmonks Re ^ 3: Reg Ex -.

- , , - "" " - Microsoft, Windows-1252, - UTF-8, Avi .

+1

, , , . , :

  • iso-8859-1 Encode:: encode.
  • ( 4 , ).
  • Then we convert the string to UTF-8 using Encode :: encode (I need this because I used the string in the iOS application and read it from the SQLite database using "NSString stringWithUTF8String:" - may not be relevant to you).

Hope this helps someone.

0
source

All Articles