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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:30:00+00:00 2026-05-25T23:30:00+00:00

I’m thinking about a special regexp problem in PHP, but I can’t find an

  • 0

I’m thinking about a special regexp problem in PHP, but I can’t find an solution.
I try to split some text into terms to get simple words, numbers and web addresses.

So i decided to split on every non alphanumeric character ( \w ).

To work with different languages, I use \w with additional letters, like Ää éèÈ and so on.

Example:

20,000 15.20 This is at Text. Right?!
www.google.com Jean Béraud

Until now, i use the following regexp to split the text:

[^\w(äÄüÜöÖßèé)]

http://regexr.com?2uq98

Which works well in 80% of cases, but splits 20,000 into 20 and 000 also http://www.google.com into www google com

So i tried to hold the numbers together, but still split on points, like Text. to get Text

To match 15.20, the following works: (\d+\.\d+), but how do I combine the negation with the other regexp string? The following will not work: (\d+\.\d+)|[^\w(äÄüÜöÖßèé)]?
And: how do I handle the web address?

  • 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-25T23:30:00+00:00Added an answer on May 25, 2026 at 11:30 pm

    Something like this?

    $result = preg_split('/\W*\s+/', $string, NULL, PREG_SPLIT_NO_EMPTY);
    

    Demo, Result:

    array(10) {
      [0]=>
      string(6) "20,000"
      [1]=>
      string(5) "15.20"
      [2]=>
      string(4) "This"
      [3]=>
      string(2) "is"
      [4]=>
      string(2) "at"
      [5]=>
      string(4) "Text"
      [6]=>
      string(5) "Right"
      [7]=>
      string(14) "www.google.com"
      [8]=>
      string(4) "Jean"
      [9]=>
      string(7) "Béraud"
    }
    

    Q: Why does \w matches é in my example?

    A: That’s based on the local of the system the PCRE library is used on, from the PHP Manual:

    A “word” character is any letter or digit or the underscore character, that is, any character which can be part of a Perl “word”. The definition of letters and digits is controlled by PCRE’s character tables, and may vary if locale-specific matching is taking place. For example, in the “fr” (French) locale, some character codes greater than 128 are used for accented letters, and these are matched by \w.

    Alternatively it might be helpful to specify the regex as working with UTF-8:

    $result = preg_split('/\W*\s+/u', $string, NULL, PREG_SPLIT_NO_EMPTY);
    

    Ensure $string is UTF-8 encoded. As UTF-8 is international, specific locale settings might not needed to be taken into account. Give it a try.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

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.