I feel like an idiot because I've spent a long time trying to find a regex that will work.
String: ~05276~^~0500~^~Turkey...
The ... means that there can be an unlimited number of characters after. What I want is the first tilde delimited number without the tildes. I'm trying to pull some data from a text file, and I think that I can figure the rest out if I can understand how to do this.
Here's my regex as it stands: /^~([\d]+)~/
This is what I'm getting:
[ '~05276~',
'05276',
index: 0,
input: '~05276~^~0500~^~Turkey...' ]
When I use the g operator (/^~([\d]+)~/g
), I'm only getting the ~05276~
, and what I want is the 05726
(no tildes).
I've found a few different posts and resources, but I can't seem to figure out why this isn't working as I expect. Here's what I found:
Javascript regex - how to get text between curly brackets
Is JavaScript/NodeJS capable of this?
Edit:
Here's my code:
lineReader.eachLine(file, function (line) {
var entry = {};
entry.id = line.match(/^~([\d]+)~/);
console.log(entry);
});
lineReader is working properly and returns a line like in my example string above.