Geekery

[Update] – a comment left by TLP gives a much better solution to the problem that seems to be better in benchmarks as well. I’m changing the post to reflect the best and fastest method for the situation described.

In a previous post, I described a situation where we needed to remove a repeating dot in a user name. In this article, I mentioned the first site that came up when searching in Google to find a solution.

I thought that I might have come across something that would be a solution for what this person was looking for. However, they clarified what they needed the function to do on their website and left me a comment with some more info:

“Thanks for citing us but the article was about making a unique chars string. For example: “aabbccaaaaaddee” will become “abcade“. That is what I accomplished in the article. I know very well regular expression and there are some way of accomplishing that but not in one step. Every char of the string must be separated by a separator (ex: comma, pipe, etc) and then apply the lookback regular expression.

The beauty of using regular expressions is this: a lot of steps that are needed to accomplish some string formating/parsing can be done in one step using RegExp. But if there are the same amount of steps it will be faster not to use RegExp.”

I love programming and I definitely love a challenge and so, webdev.andrei: I accept your challenge.

$str = 'aabbccaaaaaddee';
echo preg_replace('{(.)\1+}','$1',$str);
//abcade

This type of simple expression is thanks to a commenter that dropped by named TLP. We’ll try break it down to see how it works. The curly braces {(.)\1+} without a number in the middle means to repeat it as many times as needed until it no longer occurs. The round brackets {(.)\1+} create something called a backreference. A backreference allows it to reuse part of the regular expression match in the expression itself. So, when it comes to the first character repeating more than once, it will replace it with a single version of itself (or $1). It then places itself back in at the location of the backslash-1 {(.)\1+}.

Throughout the night until the wee hours of the morning I was furthering my ‘regex-fu’. I ultimately came to a simple loop that seems to satisfy the issue.

$string = 'aabbccaaaaaddee';
$new_string = '';
$starting_char = 0;
while (strlen($string) > 0 && $starting_char < strlen($string)) {
    $blah = preg_match('/[A-z]{2,}/', $string, $matches);
    $letter = $matches[0][$starting_char];
    $new_string .= $letter;
    $regex = '/' . $letter . '{2,}/';
    $string = preg_replace($regex, $letter, $string);
    $starting_char++;
}
echo $new_string;

In short: it tries to find a repeating character. When it finds one, it replaces it with a single version of itself. Now that it knows the first repeating instance is now a single character in the string, it can move on to the next character of the string and try that one out. It does this until there are only single instances of each character left in the string.

And there you have it. This could be done with any number of different characters by altering the first line of the loop and inputting a different range of characters instead of [A-z].

I hope this helps others and especially hope that webdev.andrei can get some use out of it.

If you liked this post, then please be sure to subscribe to my feed.

Geekery

While at work I came to an interesting conundrum when trying to validate/clean user names for the application I work on. Here is a description of the restrictions we put on our user names:

“ID may consists of A-Z, a-z, 0-9, underscores, and a single dot (.).”

While the project development staff is extremely talented, we didn’t have anyone who was particularly amazing with regular expressions. I decided to go ahead and take the plunge and start to do some research into the subject. I took a look around the internet and within the PHP documentation and couldn’t find an example of exactly what I was looking for. In fact, while searching for “php remove repeating character in string,” the first article listed in Google included a note at the bottom stating:

“I tried to have the same result using regular expressions but no success. If anyone resolved this using RegExp please share :).”

It was evident I was going to dive into the wonderful world of regex on my own. Our other filtering functions were easy enough. We have ranges of acceptable characters and some RFC-type reg-ex checks on many of our inputs that we let our users submit. In most cases running through something like this:

cFilter::clean_variable($variable);

This would run a preg_replace with the necessary regex expression and remove the bad stuff.

The challenging part was enforcing the single character. Here’s why. Let’s assume that someone wants to enter the user name of ‘cool…guy‘. First note: I am escaping the ‘.’ character with a backslash (‘\’).

$nickname = 'cool...guy';
if (ereg("\.{2,n}", $nickname, $reg)) {
    echo var_dump($reg);
}

This code produces the following output:

array(1) { [0]=> string(3) "..." }

So, if we were to run a replace using the simple “\.{2,n}”, we would end up blowing away all the dots. But that’s not what we’re looking for because the user is allowed to have one dot in their name. So, simply replacing the offending area with black characters was not going to work.

The second iteration I came up with was the following:

while (ereg("\.{2,}", $string, $reg)) {
    $string = str_replace($reg[0], ".", $string);
}

If you are familiar with PHP, you can probably see that I am using ereg with str_replace. So, why not just use ereg_replace? Well, that’d be a great plan. Here’s what I finally came up with:

$new_string = ereg_replace("\.{2,}", ".", $string);

So, if you wanted to use a different character, here’s an example of what you can do with this line of thinking. In this case, we want them to be able to have an ‘n’ in their name, but only one:

$string = 'coolnness';
$new_string = eregi_replace("n{2,}", "n", $string);
echo $new_string;

If you wanted to remove the offending characters all together, then use a blank character identifier in place of the second parameter like so:

$new_string = eregi_replace("n{2,}", "", $string);

Hope this helps someone else ’cause it sure took me a while to figure out. If you liked this post, please be sure to subscribe to my feed.

List

My fiancĂ© and were recently engaged (vid) and as such, we started looking for a new place to be our own in the Missoula, MT area. Looking in the paper always seemed to offer dated listings and some newspapers favor some property management places over others which makes for a slanted view of what is available. The image that appears below is from the web application that I’ve been working on called Grūpthink. This is the results of users of the Missoula grūp rating some of these places. Just click on the image and you can see comments and ratings for the major property management places in Missoula. I found this to be the best resource to help me get started.

Click to vote or add a new answer!

However, what I couldn’t find was a resource which listed all the different property management companies available with the necessary details such as the phone number, website, etc. In addition, some websites did not list their hours of operation so I had to call to find out. Hopefully this guide will help you out in your online search for the perfect rental in Missoula, MT.

I will list the top 10 in the order they appear in the Grūpthink topic as of Tuesday March 25th, 2008. Along with each listing you’ll find the phone number, a link to the address in Google Maps and a review of the listings on their website.

  • Garden City Property Management
    Phone: (406) 549-6106
    Address: 422 Madison St, Missoula, MT 59802
    Hours: Mon – Thurs — 8:30am – 5:30pm
    Fri — 8:30am – 5:00pm
    Sat — 9:00am – 1:00pm

    Online Listings: (link)
    The listings are updated frequently and it lists them all in a very readable and understandable format. There are not photos available for every property and some of the photos are for other units. Overall it is a simple website that runs rather quickly. Ultimately, Bonnie and I decided upon this rental agency. The staff were helpful and friendly and the price was right.

  • Grizzly Property Management
    Phone: (406) 542-2060
    Address: 1601 South Avenue West, Missoula, MT 59801
    Hours: Mon – Fri — 9:00am – 5:00pm

    Online Listings: (link)
    The website is usable and well organized. They have a lot of photos to go with their properties and good descriptions as well. However, you cannot view many different types of properties at the same time. You are, instead, confined to look at only 2 bedrooms or only studios. In addition, you have to click and look at a property to see what utilities are included rather than having them all listed out together. They have plenty of information about the company and the staff was friendly when I called.

  • Biterroot Property Management, Inc.
    Phone: (406) 549-9631
    Address: 414 W. Broadway, Missoula, MT 59802
    Hours: Mon – Fri — 8:30am – 5:00pm

    Online Listings: (link)
    This is another website that is well designed and quick. It offers photos for many of the properties as well as an easy to read and understand layout. Here, again, you are restricted to only looking at certain listings rather than viewing many. Overall, the listings are helpful and up to date and the staff was friendly on the phone.

  • Summit Property Management, LLC.
    Phone: (406) 549-3929
    Address: 500 N. Higgins Suite #208, Missoula, MT 59802
    Hours: Mon – Fri — 8:30am – 5:00pm

    Online Listings: (link)
    When Bonnie and I were searching last year, there were many more properties listed. However, this is no longer true. The website is informative and there are photos of the properties. However, as of this writing, there are only 3 properties listed in the 2 bedroom residential section. Overall the website could use a face-lift but it works.

  • Lambros Real Estate
    Phone: 1-888-735-RENT
    Address: 3011 American Way, Missoula, MT 59802 (rental office)
    Hours: Mon – Fri — 8:00am – 5:30pm

    Online Listings: (link)
    The website offers some very detailed listings and the ability to modify your searches. However, you cannot look at only residential listings. You must choose a category of listings (1 bedroom, 2 bedroom, etc.) or include commercial listings in your search which is annoying. Overall, the website is pretty well done and very functional. The listings are usually full of detailed photos.

    The comments from the users of Grūpthink do not offer very good reviews of this rental organization. You can see what some of them had to say here. The person who I spoke to on the phone was helpful and friendly.

  • Clark Fork Realty
    Phone: (406) 728-2621
    Address: 512 W. Broadway, Missoula, MT 59802
    Hours: Mon – Fri — 8:30am – 5:00pm

    Online Listings: (link)
    This website offers a list of all the rental properties with a photo if one is available. Overall, the design of the site is a bit clunky, but the detailed listings are informative. However, like some other sites, you have to click into the listing in order to find out what utilities are paid.

  • Professional Property Management, Inc.
    (not to be confused with Professional Property Management Company)
    Phone: (406) 721-8990
    Address: 2685 Palmer Suite B, Missoula, MT 59802
    Hours: Mon – Fri — 9:00am – 5:00pm

    Online Listings: (link)
    The first thing I noticed about the site was PHP 3 which, is a bit dated. However, the site is not too bad. There are photos of a lot of the different locations. However, the big gripe that I have, is that many of their listings have no vacancies. This means that while searching, you might see a perfect property in the list, only to click on it and find out it is not available. In short: don’t list a property if it isn’t available.

  • Caras Property Management (other site)
    Phone: (406) 543-9798
    Address: 125 E Main St, Missoula, MT 59802
    Hours: Mon – Fri — 8:30am – 5:00pm

    Online Listings: (link, link)
    The first problem is that they have two websites for the same properties. Both websites display errors on some of the pages. The listings do contain helpful information such as the average utilities, but then, it depends on what site you’re looking at. Overall, they should pick one website and go with it. Just have the other forward to one. Unfortunately, the websites alone make this property management company seem to be far behind their competition.

  • Missoula Property Management
    Phone: (406) 251-8500
    Address: 2809 Great Northern Loop, Missoula, MT 59801
    Hours: Mon – Fri — 9:00am – 5:00pm

    Online Listings: (link)
    There are none. This is disappointing considering the necessity for most to utilize online listings for making a decision for a rental property. In addition, the site has visible areas and offers a great deal of information about the company, but little to do with their listings. In addition, the address listed on the site is not the address I was given over the phone (I listed the latter). Overall, you’d be better off giving them a call.

Well there you have it. The top 10 online property management places for Missoula, MT. I hope you find this guide helpful. If you enjoyed this post then be sure to subscribe to my RSS feed. If you would like your website to be listed here, then send an email to writer at ilovebonnie.net.