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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:35:12+00:00 2026-06-11T14:35:12+00:00

I have a regex which will split my string into arrays. Everyything works fine

  • 0

I have a regex which will split my string into arrays.

Everyything works fine except that I would like to keep a part of the delimiter.

Here is my regex:

(&#?[a-zA-Z0-9]+;)[\s]

in Javascript, I am doing:

var test = paragraph.split(/(&#?[a-zA-Z0-9]+;)[\s]/g);

My paragraph is as followed:

Current addresses:  &dagger;    Biopharmaceutical Research and Development<br />
&Dagger;    Clovis Oncology<br />
&sect;  Pisces Molecular <br />
||  School of Biological Sciences    
&para;  Department of Chemistry<br />

The problem is that I am getting 10 elements in my array and not 5 as I should. In fact, I am also getting my delimiter as an element and my goal is to keep the delimiter with the splited element and not to create a new one.

Thank you very much for your help.

EDIT:

I would like to get this as a result:

1. &dagger; Biopharmaceutical Research and Development<br />
2. &Dagger; Clovis Oncology<br />
3. &sect;   &sect;  Pisces Molecular <br />
||  School of Biological Sciences  
4.  &para;  Department of Chemistry<br />
  • 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-11T14:35:13+00:00Added an answer on June 11, 2026 at 2:35 pm

    Try to use match instead:

    var test = paragraph.match(/&#?[a-zA-Z0-9]+;\s[^&]*/g);
    

    Updated: Added a required white-space \s match.

    Explanation:

    • &#? Match & and an optional # (the question mark match previous one or zero times)

    • [a-zA-Z0-9] is a range of all upper and lower case characters and digits. If you also accept an underscore you could replace this with \w.

    • The + sign means that it should match the last pattern one or more times, so it matches one or more characters a-z, A-Z and digits 0-9.

    • The ; matches the character ;.

    • The \s matches the class white-space. That includes space, tab and other white-space characters.

    • [^&]* Once again a range, but since ^ is the first character the match is negated, so instead of matching the &-characters it matches everything but the &. The star matches the pattern zero or more times.

    • g at the end, after the last / means global, and makes the match continue after the first match and get an array of all matches.

    So, match & and an optional #, followed by any number of letters or digits (but at least one), followed by ;, followed by a white-space, followed by zero or more characters that isn’t &.

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

Sidebar

Related Questions

^(.)+\S{10}(.)+$ I have that regex which will match any string that contains a word
I have a JS function which is passed a string that a RegEx is
I would like a regex which will return words between _ word1_word2_word3_word4_word5 I want
I have a regex which will match the string 'test', but I want it
How I love regex! I have a string which will be a mangled form
I need to write a regex which will match URLs that do not have
I have created a function which will convert any string into tab delimited. What's
I have a javascript regex which validates UK postcodes. It works well, but it
Hi have this URL string which I need to extract possibly using regex but
Is this Regex correct if I have to match a string which is atleast

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.