You may try a regex string split here:

var inputs = ["£____", "____$", "42____$"];
for (var i=0; i < inputs.length; ++i) {
    var parts = inputs[i].split(/_+/);
    console.log("before = " + parts[0] + ", after = " + parts[1]);
}

Answer from Tim Biegeleisen on Stack Overflow
Discussions

How do I have JavaScript get a substring before a character? - Stack Overflow
Let's say I have a paragraph that says 55+5. I want to have JavaScript return everything before the plus. Is this possible using substrings? More on stackoverflow.com
🌐 stackoverflow.com
September 20, 2016
javascript - How to return part of string before a certain character? - Stack Overflow
Sorry all, I got my before and after messed up... so I am wanting to display the Abc not the Lorem ipsum sit amet. Thanks. ... You fiddle already does the job ... maybe you try to get the string before the double colon? More on stackoverflow.com
🌐 stackoverflow.com
December 30, 2018
jquery - javascript get string before a character - Stack Overflow
I have a string that and I am trying to extract the characters before the quote. More on stackoverflow.com
🌐 stackoverflow.com
August 26, 2012
javascript - Getting values before and after characters "-" in a String - Stack Overflow
I have the following string variable in Javascript; var str = "12-134, 65-598, 100-210, 857-34, 3-21, 89-103". I'd like to return all the values before and after "-" separately. That is before "-... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Flavio Copes
flaviocopes.com › home › javascript › javascript, how to get string until character
JavaScript, how to get string until character - Flavio Copes
July 24, 2022 - Learn how to get the part of a string before a specific character in JavaScript using split, a quick one-liner that returns everything up to that point.
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-string-exercise-22.php
JavaScript validation with regular expression: Get a part of string after a specified character - w3resource
July 17, 2025 - // Define a function named subStrAfterChars with parameters str (input string), char (character to search for), and pos (position indicator). function subStrAfterChars(str, char, pos) { // If the position indicator is 'b' (before), return the ...
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-get-substring-before-specific-character
Get the Substring before a specific Character in JavaScript | bobbyhadz
If your string contains multiple occurrences of the character and you need to get the substring up to the last occurrence of the character, use the String.lastIndexOf() method instead.
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-get-a-part-of-string-after-a-specified-character-in-javascript
How to get a part of string after a specified character in JavaScript?
July 30, 2019 - Using substring() with indexOf() provides a reliable way to extract text before or after any specified character. This technique is commonly used for parsing strings like URLs, file paths, and email addresses. vineeth.mariserla · Updated on: ...
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-get-substring-after-specific-character
Get the Substring after a specific Character in JavaScript | bobbyhadz
The indexOf() method returns the index of the first occurrence of the character and we use the String.slice() method to get a slice of the string after the character. You can learn more about the related topics by checking out the following ...
Find elsewhere
🌐
Linux Hint
linuxhint.com › get-substring-before-specific-character-javascript
Linux Hint – Linux Hint
Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
Sabe
sabe.io › blog › javascript-get-substring-after-specific-character
Get the Substring after a Specific Character in JavaScript | Sabe
May 10, 2022 - Here's a more condensed version ... specific character. Simply combine the indexOf() and substring() methods to get the index of the specific character, then use it to get the substring after it....
🌐
Futurestud.io
futurestud.io › tutorials › get-the-part-before-a-character-in-a-string-in-javascript-or-node-js
Get the Part Before a Character in a String in JavaScript or Node.js
const Str = require('@supercharge/strings') Str('A1:L200').before(':').get() // 'A1' Str('2020-this-is-a-tutorial-slug').before('-').get() // '2020' ... Get your weekly push notification about new and trending Future Studio content and recent platform enhancements
🌐
Futurestud.io
futurestud.io › tutorials › get-the-part-before-first-occurrence-in-a-string-in-javascript-or-node-js
Get the Part Before First Occurrence in a String in JavaScript or Node.js
February 3, 2022 - It provides a useful Str#before method returning the part of a string before the given character(s): const Str = require('@supercharge/strings') Str('Future Studio is an awesome island').before('is') // 'Future Studio ' Str('Future Studio is an awesome island').before('great') // 'Future Studio ...