Solved

Regular Expression for matching Hex a0 two capital letters then a0

Posted on 2008-10-31
4
1,378 Views
Last Modified: 2012-05-05
Trying to write a Perl Regular to accomplish the following given:

LAKE ST LOUIS MO 63367­1348

the spaces are not normal HEX 20, but are in fact HEX A0...

I am trying to parse this type of string to City, State, Zip fields...

The state isn't always MO this is just an example.

I suck at complicated regular expressions.

I tried /\xa0[A-Z][A-Z]\xa0/   but doesn't seem to work right.

Any help greatly appreciated!
Dan


0
Comment
Question by:dyoung520
  • 2
4 Comments
 
LVL 27

Expert Comment

by:ddrudik
ID: 22852825
You shuld be able to match a non-breaking space ascii 160 hex \xa0 with the pattern as shown.

In php:
<?php
echo preg_match('/\xa0/',chr(160)) ? "found non-breaking space" : "not found";
?>

Is it possible those are \x20 instead, here's how your string appears in regex (as pasted above):
^LAKE\x20ST\x20LOUIS\x20MO\x2063367\xC2\xAD1348$
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 22852890
$_ = "LAKE ST LOUIS\xa0MO\xa063367­1348";
print /(\xa0[A-Z][A-Z]\xa0)/
 MO
0
 

Author Comment

by:dyoung520
ID: 22853326
Really the problem is I'm just an idiot!!!

LAKE\xa0ST\xa0LOUIS\xa0MO\xa063367­1348

That's how the string looks...  Why was I having a problem??

Because "ST" matches - see I'm an Idiot :-)

Thanks for your help... I still would not have seen my error without seeing your posts!

0
 

Author Closing Comment

by:dyoung520
ID: 31512149
You proved to me I'm an idiot!  I've been saying this for years and people around me don't believe me... Thanks Again!!!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question