Solved

Regular Expression for matching Hex a0 two capital letters then a0

Posted on 2008-10-31
4
1,375 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

785 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