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

  • Home
  • SEARCH
  • 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 8316261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:19:22+00:00 2026-06-08T21:19:22+00:00

I have a string something like: foo title:2012-01-01 bar Where I need to get

  • 0

I have a string something like:

foo title:2012-01-01 bar

Where I need to get the ‘title:2012-01-01’ and replace the date part ‘2012-01-01’ to a special format. I just am not good at RegExp and currently have:

'foo from:2012-01-01 bar'.replace(/from:([a-z0-9-]+)/i, function() {
    console.log(arguments);
    return 'replaced';
})

and that returns

foo replaced bar 

which is a start but not exactly correct. I need the ‘from:’ not to be replaced, just the ‘2012-01-01’ be replaced. Tried using (?:from:) but that didn’t stop it from replacing ‘from:’. Also, I need to take into account that there may be a space between ‘from:’ and ‘2012-01-01’ so it needs to match this also:

foo title: 2012-01-01 bar
  • 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-08T21:19:24+00:00Added an answer on June 8, 2026 at 9:19 pm

    The following should do what you need it to; tested it myself:

    'foo from:2012-01-01 bar'.replace(/(\w+:\s?)([a-z0-9-]+)/i, function(match, $1) {
        console.log(arguments);
        return $1 + 'replaced';
    });
    

    DEMO

    It will match both title: etc and from:etc. The $1 is the first matched group, the (\w+:\s?), the \w matches any word character, while the \s? matches for at least one or no spaces.

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

Sidebar

Related Questions

I have a string 2010-08-02 12:13:06.0 and need to get something like Fri Aug
I have a string that looks something like the following: 12,44,foo,bar,(23,45,200),6 I'd like to
I have a string: Something 8:45 foo bar foo bar at 23:50 How to
I have a hive table like CREATE TABLE beacons ( foo string, bar string,
it appears if you have something like var my_var = {foo : bar}; in
I have a hierarchical descriptor string that looks like foo:bar:baz where elements in the
Let's say I have a class like: public class Foo { public string Title
I have a string that contains something like this: ##### abc 'foo' /path/to/filename:1 #####
I have a string like this: Name foo Modified bar I want to split
I have a string containing something like this Hello bla bla bla bla ok,

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.