Solved

Regular Expression for matching Hex a0 two capital letters then a0

Posted on 2008-10-31
4
1,388 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…

737 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