Match hex value in string (Perl)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Match hex value in string (Perl)
# 1  
Old 07-12-2010
Match hex value in string (Perl)

I am trying to match a character return from a website so that I can replace it. It is the '...' character (didnt even know it existed initially). The character apparently has the hex value of 2026, but in the script, attempting to substitute regular 3 periods is not working.

What am I missing?

Code:
$plot =~ s/\x20\x26/.../g;
$plot =~ s/\.../.../g;
$plot =~ s/\x2026/.../g;

None of these are working, and I am not sure where to go from here.. Suggestions on a direction to take this would be greatly appreciated!

Chris

---------- Post updated at 01:26 PM ---------- Previous update was at 01:09 PM ----------

As I have continued googling on this problem, it is looking like this is a true unicode character, so I have also tried \u2026 as well
# 2  
Old 07-12-2010
I'm not familiar with perl's unicode capabilities, but assuming that the unicode 2026 character is encoded in utf8, a non-unicode/utf-8 aware approach will have to match a sequence of three bytes: 0xE2 0x80 0xA6.

Unicode Character 'HORIZONTAL ELLIPSIS' (U+2026)

Code:
$ printf '\xe2\x80\xa6\n' | perl -lne 'print "MATCHED: $_" if /\xe2\x80\xa6/'
MATCHED: …

Regards,
Alister

Last edited by alister; 07-12-2010 at 07:22 PM..
# 3  
Old 07-19-2010
Quote:
Originally Posted by alister
I'm not familiar with perl's unicode capabilities, but assuming that the unicode 2026 character is encoded in utf8, a non-unicode/utf-8 aware approach will have to match a sequence of three bytes: 0xE2 0x80 0xA6.

Unicode Character 'HORIZONTAL ELLIPSIS' (U+2026)

Code:
$ printf '\xe2\x80\xa6\n' | perl -lne 'print "MATCHED: $_" if /\xe2\x80\xa6/'
MATCHED: ...

Regards,
Alister
Thanks! Thats exactly what I needed!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Using sed to split hex string

Hi, I'm looking to split the following hex string into rows of four elements. I've tried the following but it doesn't seem to work. How can I tell sed to match based on a pair of number(s) and letter(s), and add a newline every 4 pairs? In addition, I need to add another newline after every... (5 Replies)
Discussion started by: sand1234
5 Replies

2. Shell Programming and Scripting

String match, with perl command

cat clinvar_00-latest.vcf | perl -aF/\\t/ -lne '/CLNSRCID=(\d+)/ and print join("\t",@F,$1)' > OMIM.txt The above code finds the text CLNSRCID=, but only outputs those records in which there is a numerical value only. For example, the first match is CLNSRCID=103320.0001 in line 4 of the... (1 Reply)
Discussion started by: cmccabe
1 Replies

3. Shell Programming and Scripting

perl regex string match issue..kindly help

i have a script in which i need to skip comments, and i am able to achieve it partially... IN text file: {**************************** {test : test...test } Script: while (<$fh>) { push ( @data, $_); } if ( $data =~ m/(^{\*+$)/ ){ } With the above match i am... (5 Replies)
Discussion started by: avskrm
5 Replies

4. Shell Programming and Scripting

Convert to Hex in perl

Hi, i want to convert number 5860533159 to hexadecimal. i need to use perl. i used $foo = 5860533159; $hexval3 = sprintf("%#x", $foo); i am getting value as 0xffffffff. i need to get value as 0x15D50A3A7. when i converted using google calculator, i got the correct value, expected... (9 Replies)
Discussion started by: asak
9 Replies

5. Shell Programming and Scripting

Perl : how to match non-empty string that has no spaces

Hi Everyone, I am looking for neat way to grep a non-empty string that basically contains a hostname, which might be in FWDN form or without the domain, for example: hostname.internal.domainname.net The file I am parsing contains blan lines (^$) and also series of "-" which in other places... (2 Replies)
Discussion started by: togr
2 Replies

6. Programming

Hex string conversion?

Hello all. I need help... How can I cenvert this 42ec93df826c804ea531c56594db453d54daad4b to normal text? What convertor I have to use? Thanks. (12 Replies)
Discussion started by: escudo
12 Replies

7. Shell Programming and Scripting

pattern match url in string / PERL

Am trying to remove urls from text strings in PERL. I have the following but it does not seem to work: $remarks =~ s/www\.\s+\.com//gi; In English, I want to look for www. then I want to delete the www. and everything after it until I hit a space (but not including the space). It's not... (2 Replies)
Discussion started by: mrealty
2 Replies

8. Shell Programming and Scripting

Perl: Better way to match string within a string

Hi, I'm trying to get one field out of many as follows: A string of multiple fields separated with "/" characters: "/ab=12/cd=34/12=ab/34=cd/ef=pick-this.one/gh=blah/ij=something/" I want to pick up the field "ef=pick-this.one" which has no regular pattern except it starts with "ef=xxxx"... (3 Replies)
Discussion started by: Juha
3 Replies

9. UNIX for Dummies Questions & Answers

hex value in a file + perl

Am not able to display the corresponding character for the hex value using the format specifier into a file Could you please help me with that >cat other a|\xc2\xbo >cat write.pl #! /opt/third-party/bin/perl open(FILE2, "< other") || die "Unable to open file other\n"; while (... (7 Replies)
Discussion started by: matrixmadhan
7 Replies

10. Programming

converting character string to hex string

HI Hi I have a character string which contains some special characters and I need it to display as a hex string. For example, the sample i/p string: ×¥ïA Å gïÛý and the o/p should be : D7A5EF4100C5010067EFDBFD Any pointers or sample code pls. (5 Replies)
Discussion started by: axes
5 Replies
Login or Register to Ask a Question