function extractSummary(iCalContent) {
  var rx = /\nSUMMARY:(.*)\n/g;
  var arr = rx.exec(iCalContent);
  return arr[1]; 
}

You need these changes:

  • Put the * inside the parenthesis as suggested above. Otherwise your matching group will contain only one character.

  • Get rid of the ^ and $. With the global option they match on start and end of the full string, rather than on start and end of lines. Match on explicit newlines instead.

  • I suppose you want the matching group (what's inside the parenthesis) rather than the full array? arr[0] is the full match ("\nSUMMARY:...") and the next indexes contain the group matches.

  • String.match(regexp) is supposed to return an array with the matches. In my browser it doesn't (Safari on Mac returns only the full match, not the groups), but Regexp.exec(string) works.

Answer from j-g-faustus on Stack Overflow
🌐
Self-Host Kutt With Docker
paulsblog.dev › manipulate-strings-with-regular-expression-in-javascript
Manipulate Strings With Regular Expressions In JavaScript
March 14, 2025 - Before going into detail and explaining ... ... Substrings can be extracted from a large String using the match() function and a Regular Expression in JavaScript....
Discussions

regex - Extract text in Regular Expression in Javascript - Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Connect and share knowledge within a single location that is structured and easy to search. Learn more about Teams ... In Javascript, I want to extract array from a string. More on stackoverflow.com
🌐 stackoverflow.com
December 19, 2018
javascript - How to extract a text using regex? - Stack Overflow
Then just take the matched string of the first group. Additionally, to only match as little as possible, make the + quantifier non-greedy by using +?. ... Sign up to request clarification or add additional context in comments. ... The group (.+) will match as much as it can (it's "greedy"). To make it find a minimal match you can use (.+?). ... JavaScript does not support lookbehinds. Make the quantifier non greedy, and use: var regex ... More on stackoverflow.com
🌐 stackoverflow.com
regex - Using Regular Expressions to Extract Values in Javascript - Stack Overflow
I have a string in the form: "xMyS" I want to extract x and y in using the Javascript Regex expressions. For example, if the string is 10M225S I need 10 and 225 from this. Also, the string mig... More on stackoverflow.com
🌐 stackoverflow.com
javascript - How to extract text using Regular expression (RegEx)? - Stack Overflow
I have the following string. var str = "SOme TEXT #extract1$ Some more text #extract2$ much more text #extract3$ some junk"; I want to extract all the text between # and $ into an array or object. ... You can use JavaScript Regular expressions' exec method. var regex = /\#([^\$]+)\$/g, match_arr, ... More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 5
134

match returns an array.

The default string representation of an array in JavaScript is the elements of the array separated by commas. In this case the desired result is in the second element of the array:

var tesst = "afskfsd33j"
var test = tesst.match(/a(.*)j/);
alert (test[1]);
2 of 5
11

Each group defined by parenthesis () is captured during processing and each captured group content is pushed into result array in the same order as groups within pattern starts. See more on http://www.regular-expressions.info/brackets.html and http://www.regular-expressions.info/refcapture.html (choose right language to see supported features)

var source = "afskfsd33j"
var result = source.match(/a(.*)j/);

result: ["afskfsd33j", "fskfsd33"]

The reason why you received this exact result is following:

First value in array is the first found string which confirms the entire pattern. So it should definitely start with "a" followed by any number of any characters and ends with first "j".

Second value in the array is captured group defined by parenthesis. In your case group contains string consist of any character with length <0; infinite). Which is entire source without starting "a" and ending "j" which are defined outside parenthesis, so exactly "fskfsd33".

If you want to get rid of second value in the array you may define pattern like this:

/a(?:.*)j/

where "?:" means that group of chars which match the content in parenthesis will not be part of the resulting array.

Other options might be in this simple case to write pattern without any group because it is not necessary to use group at all:

/a.*j/

If you want to just check whether source text matches the pattern and does not care about found texts then you may try:

var result = /a.*j/.test(source);

The result should return then only true|false values. For more info see http://www.javascriptkit.com/javatutors/re3.shtml

I would recommend test page https://regex101.com/ where you can test the patterns with full explanation how the RegExp works.

🌐
DEV Community
dev.to › swarnaliroy94 › part-3-match-and-extract-a-regex-with-match-method-4iog
Part 3 : Match and Extract a REGEX with .match() Method - DEV Community
August 6, 2021 - Let's go through a simple example of .match() method: let extractStr = "Extract the word coding from this string."; let codingRegex = /coding/; let result = extractStr.match(codingRegex); console.log(result); /* output: [ 'coding', index: 17, ...
🌐
Learn JS Data
learnjsdata.com › regexes.html
Data manipulation, cleaning, and processing in JavaScript
They can be a useful tool for extracting patterns rather than exact strings, for example: telephone numbers (sequences of numbers of a specific length,) street numbers or email addresses. var str = "how much wood would a woodchuck chuck if a woodchuck could chuck wood"; var regex = /wood/;
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Regular_expressions
Regular expressions - JavaScript - MDN Web Docs
This allows you to do new RegExp(RegExp.escape("a*b")) to create a regular expression that matches only the string "a*b". Parentheses around any part of the regular expression pattern causes that part of the matched substring to be remembered. Once remembered, the substring can be recalled ...
Find elsewhere
🌐
javaspring
javaspring.net › blog › regular-expression-to-get-a-string-between-two-strings-in-javascript
How to Use Regular Expressions to Extract a String Between Two Strings in JavaScript — javaspring.net
A regular expression is a sequence of characters that defines a search pattern. In JavaScript, regex can be used to match, test, replace, or extract text from strings.
🌐
Flavio Copes
flaviocopes.com › home › javascript › how to use javascript regular expressions
How to use JavaScript Regular Expressions - Flavio Copes
July 18, 2026 - Learn how to use JavaScript regular expressions to search, validate, extract, and replace text, with practical examples of patterns, groups, and flags. ... A regular expression, also called a regex, is a pattern used to search and transform text.
🌐
JavaScript.info
javascript.info › tutorial › regular expressions
Methods of RegExp and String
Splits the string using the regexp (or a substring) as a delimiter. ... let str = "A drop of ink may make a million think"; alert( str.search( /ink/i ) ); // 10 (first match position) The important limitation: search only finds the first match.
🌐
YouTube
youtube.com › watch
JavaScript Regular Expressions: Extract Matches | FreeCodeCamp - YouTube
🍂 **"Whispers from the Text: The Enchanted Dance of Extraction"** 🌙🔗Main Page Link: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-stru...
Published: September 17, 2023
🌐
Reddit
reddit.com › r/regex › extracting a substring using capture groups
r/regex on Reddit: Extracting a substring using capture groups
July 6, 2022 -

Hey!

So I am currently trying to extract a substring out of another string using Regex capture groups in JavaScript. However, it doesn't really work since my Regex matches the entire string only.

This is the string I am working with:

'"updateUsersRoom",{"room":"room_name","userid":111,"imgthumb":"some.png"}]'

This is the part I wanna extract:

'{"room":"room_name","userid":111,"imgthumb":"some.png"}'

Note

The following case is also possible:

'"someEvent", 1234]'

Here I'd want to extract

'1234'

The regular expression I am currently using is:

const eventDataRegex = new RegExp(`"${eventName}",(.*)]`, 'g'); 
-> resolves to /"updateUsersRoom",(.*)]/g for example

The result I am receiving using JavaScript's provided Str.match() function is the entire string, no groups whatsoever.

Example result:

[
  '"updateUsersRoom",{"room":"room_name","userid":111,"imgthumb":"some.png"}]'
]

Can anyone help me out on this one? I only recently stated using regex :)

Thank you all in advance!

🌐
Honeybadger
honeybadger.io › blog › javascript-regular-expressions
The ultimate JavaScript regex guide - Honeybadger Developer Blog
May 9, 2025 - JavaScript has a RegExp constructor that you can use to create regex patterns. You pass the pattern as a string argument to the constructor:
🌐
Danburzo
danburzo.ro › string-extract
Extracting things from JavaScript strings · Dan Cătălin Burzo
August 19, 2016 - var str = "Top 10 videos this months: \ 1. [youtube:FyCsJAj69sc] \ 2. [vimeo:128373915]"; var shortcode_regex = /\[(\w+):(\w+)\]/g; var matches = []; str.replace(shortcode_regex, function(match, code, id) { matches.push({ code: code, id: id }); }); console.log(matches);