Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editing Database Text 1

Status
Not open for further replies.

Bergler

ISP
Oct 13, 2006
3
US
I inherited a perl script for a website that I maintain. It pulls a delimited text file from a real estate site and inserts it into a MySQL database. There is one portion of the script that doesn't work quite right.

# Remove "Lake/River: "
if ($data =~ m!LAKE/RIVER: (\w+)!) {
$data = ucfirst(lc($1));
}

The actual data reads as "Lake/River: Rice" or "Lake/River: St. Germain". The script is supposed to reomve the text "Lake/River:" and just return "Rice" or "St. Germain". For the one-word lakes like "Rice" it works fine, but for "St. Germain" all it returns is "St.". It stops when it hits a space. Any idea on how to make it pick up both words?
 
Replace:
Code:
(\w+)
with:
Code:
(.+)$
The original wants a continuous set of word-characters, so it stops at the first non-word character, which is the '.', but it would stop at the space also. The replacement will simply return everything. You can make this as complex as you like; this:
Code:
(\w([-\w\s\.'\(\)]*\w)?)
will limit itself to word and space characters, plus the nominated punctuation marks . , ' ( and ) but the match must begin and end with a word character.
 
Thank you very much. That was fast and it did the trick.
 
have a star Morac!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top