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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:41:36+00:00 2026-05-20T13:41:36+00:00

Trying to parse the following text: This is one of the [name]John’s[/name] first tutorials.

  • 0

Trying to parse the following text:

This is one of the [name]John’s[/name]
first tutorials.

or

Please invite [name]Steven[/name] to
the meeting.

What I need is to do a regexp in Javascript to get the name.
Doing var str = body.match(/[name](.*?)[\/name]/g); works, but how do I get just the inside of it?

  • 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-20T13:41:37+00:00Added an answer on May 20, 2026 at 1:41 pm

    Try using the “exec” method of a regular expression to get the matching groups as an array:

    var getName = function(str) {
      var m = /\[name\](.*?)\[\/name\]/.exec(str);
      return (m) ? m[1] : null;
    }
    
    var john = getName("This is one of [name]John's[/name] first tutorials.");
    john // => "John's"
    var steve = getName("Please invite [name]Steven[/name] to the meeting.");
    steve // => "Steven"
    

    This could be easily extended to find all occurrences of names by using a global RegExp:

    var getAllNames = function(str) {
      var regex = /\[name\](.*?)\[\/name\]/g
        , names = []
        , match;
      while (match = regex.exec(str)) {
        names.push(match[1]);
      }
      return names;
    }
    
    var names = getAllNames("Hi [name]John[/name], and [name]Steve[/name]!");
    names; // => ["John", "Steve"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm trying to a parse a file that has text in this format:
I'm tearing my hair off my head on this one. Trying to parse this
I have the following text that I am trying to parse: user1@emailaddy1.com <user1@emailaddy1.com>, Jane
I am trying to parse following text in variable... $str = 3,283,518(10,569 / 2,173)
I am trying to parse the following JSON string remotely: [{name:Object1,data:[1,2]},{name:Object2,data:[3,4]}] I am doing
I am trying to parse the following XML with javascript: <?xml version='1.0' encoding='UTF-8'?> <ResultSet>
So I'm trying to parse the following XML document with C#, using System.XML: <root
What I'm trying to do this is writing a simple parser for the following
Trying to parse an HTML document and extract some elements (any links to text
Trying to parse some XML but apparently this is too much for a lazy

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.