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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:57:05+00:00 2026-05-17T16:57:05+00:00

Apart from what they are, I dont know anything about regular expressions… :( I

  • 0

Apart from what they are, I dont know anything about regular expressions… 🙁

I have this code in a javascript function:

var foroFormatting = function (text) {
    var newText = text;
    var findreps = [
        { find: /^([^\-]+) \- /g, rep: '<span class="ui-selectmenu-item-header">$1</span>' },
        { find: /([^\|><]+) \| /g, rep: '<span class="ui-selectmenu-item-content">$1</span>' },
        { find: /([^\|><\(\)]+) (\()/g, rep: '<span class="ui-selectmenu-item-content">$1</span>$2' },
        { find: /([^\|><\(\)]+)$/g, rep: '<span class="ui-selectmenu-item-content">$1</span>' },
        { find: /(\([^\|><]+\))$/g, rep: '<span class="ui-selectmenu-item-footer">$1</span>' }
    ];
    for (var i in findreps) {
        newText = newText.replace(findreps[i].find, findreps[i].rep);
    }
    return newText;
}

This code expect a string like this

John Doe - 78 West Main St Apt 3A | Bloomsburg, PA 12345 (footer text)

and split it in four span elements right?

I would like to apply the same formatting to a string that is a bit different from that

John Doe - 78 West Main St Apt 3A | Bloomsburg, PA 12345

How do I have to modify the regular expression?

EDIT

I am trying to use this plugin (third example) with a string of mine that is different from the original just in the last part

  • 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-17T16:57:06+00:00Added an answer on May 17, 2026 at 4:57 pm

    If all you are dropping is just (footer text), then the same function without the last replacement regex will work.

    var foroFormatting2 = function (text) {
        var newText = text;
        var findreps = [
            { find: /^([^\-]+) \- /g, rep: '<span class="ui-selectmenu-item-header">$1</span>' },
            { find: /([^\|><]+) \| /g, rep: '<span class="ui-selectmenu-item-content">$1</span>' },
            { find: /([^\|><\(\)]+)$/g, rep: '<span class="ui-selectmenu-item-content">$1</span>' }
        ];
        for (var i in findreps) {
            newText = newText.replace(findreps[i].find, findreps[i].rep);
        }
        return newText;
    }
    

    I’ve removed the parts that captured and formatted (footer text). I suggest reading up on regular expressions. They are a great tool.

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

Sidebar

Related Questions

Apart from jQuery, which other JavaScript libraries support Visual Studio2005/2008 intellisense integration?
The following code works in all browsers apart from IE6... var mylib = {
When I try to run my code on any other webbrowsers apart from the
Apart from C++, which non-toy languages have direct or easy-to-use compatibility to C? As
I have a few view helpers that add JavaScript files when they're needed (for
The following code shows a dialog as expected, apart from having no buttons: final
Apart from what is shown in the NXP websites regarding mifare plus and mifare
Apart from lxml , is anyone aware of Python packages that depend on libxml2
Apart from Sql server profiler ,is there any third party user friendly tool available
Apart from main thread, I've ThinkerThread object _thinker whose finished() signal is connected to

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.