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 8914459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:43:23+00:00 2026-06-15T04:43:23+00:00

I have these types of possible content in the strings I’m breaking up: $string

  • 0

I have these types of possible content in the strings I’m breaking up:

$string = "$100 USD per year"
$string = "$100USD per year"
$string = "100 USD per year"
$string = "100EUR per year"
$string = "€100EUR per year"
$string = "€100 EUR per year"

This is the regular expression I am using (and it works in Expresso):

$pattern = "/\$?(\d+\.\d+)(\w{0,3})\s(.*)/i";

Basically, I want the end result to be an array like the following:

$arr[0] = "$100" // the "$" optional, also number might be integer or decimal
$arr[1] = "USD";
$arr[2] = "per year";

This is the sample PHP code I’m running but to no avail:

<?php
$content = "$99.37CAD per year";

$pattern = "/\$?(\d+\.\d+)(\w{0,3})\s(.*)/i";

$myArr = preg_split($pattern, $content);

echo "<pre>";
var_dump($myArr);
echo "</pre>";
?>

And the output is:

bool(false)

Can someone please point me in the right direction?

  • 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-06-15T04:43:25+00:00Added an answer on June 15, 2026 at 4:43 am

    The problem is that the SPACE between the price and the EUR/CAD/USD, is not optional. So you just have to add a * to it, like \s*. With that you will tell RegEx that that space is optional so it can be or not.

    Another thing is that you must match, not split. With the decimal digits optional.

    DEMO Regex: [$€]?(\d+(?:\.\d+)?)\s*(\w{0,3})\s*(.*)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these simplified types: public class DataBean extends ZZZZZ { public String name;
I have these tables: Idea and poll (and others) which are types of what
I have 2 custom post types - offered and wanted. I want these items
I have some models; Vocabularies (tags lists), Labels (tags) and different articles types. These
In my Java project, I have a vector of various types of Traders. These
Possible Duplicate: Only primitive types (‘such as Int32, String, and Guid’) are supported in
I have these text inputs in a table : <td><input type='text' name='arrondi_devis_ht' class='calcul_total' size='8'></td>
I have read a document that they say: In java there two types of
I have defined a custom file type with these lines: syn region SubSubtitle start=+=+
Are there exceptions for types which can't have thier assignment operator overloaded? Specifically, I'm

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.