Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6354415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:34:20+00:00 2026-05-24T22:34:20+00:00

I borrowed the script used by SteamCalculator.com and wanted to modify it slightly to

  • 0

I borrowed the script used by SteamCalculator.com and wanted to modify it slightly to grab not just the price of the games on Steam, but the sale prices as well (if they exist)

The code was extremely straight-forward and easy enough to read. To retrieve the price he looks at the HTML from the steampowered.com search feature, pulls out everything between <div class=\"col search_price\"> and </div>, then runs the following sub-routine:

sub formPrice($)
{
    my $price = shift;

    if($price =~ m/(\d+)(?:\.|,)(\d{2})/)
    {
        return $1.$2;
    }
    else
    {
        return 0;
    }
}

The price is able to take one of 4 forms, depending on the country code you are looking for prices in and whether or not the game is on sale. These four forms are:

$9.99
<span><strike>$9.99</strike></span><br>$8.99
9,99£
<span><strike>9.99£</strike></span><br>8,99£

As you can see, regardless of which form the price takes his script will grab the very first instance of (\d+) (first group of digits, returning 9 in every case) as well as the (\d{2}) (group of 2 digits) following \.|, (dot or comma). When these are combined the sub-routine always returns 999, regardless of which of the four formats the price has.

I’ve been trying to find a way to modify this sub-routine to return 999 in cases 1 and 3, but return 899 in cases 2 and 4. So far I have tried:

1:

if((reverse $price) =~ m/(\d+)(?:\.|,)(\d{2})/g){
    return $2.$1;
}

2:

if($price =~ m/.*?(\d+)(?:\.|,)(\d{2})/g){
    return $1.$2;
}

3:

if($price =~ m/.*?(\d+)(?:\.|,)(\d{2})$/){
    return $1.$2;
}

The first returned prices such as 9199 for $19.99. The second the .*? was still being greedy and it was returning 999 for $19.99. The third returned 0 in cases 3 and 4 (dealing with euros)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:34:21+00:00Added an answer on May 24, 2026 at 10:34 pm

    Anchoring the end as Flimzy suggests is the easiest solution.

    I’m curious what you were trying to accomplish with your second attempt:

    if($price =~ m/.*?(\d+)(?:\.|,)(\d{2})/g){
        return $1.$2;
    }
    

    Adding the g doesn’t do anything particularly useful in this case. Adding .* (not .*?) to the beginning does get you the last match instead of the first, but you do need to guard against the match starting later than you want, e.g.:

    if ( $price =~ m/.*\b(\d+)(?:\.|,)(\d{2})/ ) {
        return $1.$2;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I borrowed the code from http://jqueryui.com/demos/autocomplete/#combobox but don't know how to get the value
Title borrowed from this question , of which this one is not a duplicate.
I borrowed some code from a site, but I don't know how to get
I borrowed the following method from somewhere on the internet (Can't remember where). But
This following code example is borrowed from MSDN here . I am not getting
I am learning AJAX and have borrowed a script from NETTUTS Codeigniter from Scratch:
I stayed up all night just trying to resolve the JQuery slideshow but I
I wanted to track some options via bitmask'ing them, and borrowed bitmask values from
I'm wondering if such a syntax (borrowed from C#, mind you) is used by
Ok, back with not necessarily a true definition of a question but need some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.