Home > Blockchain >  Regex to get all characters AFTER first comma
Regex to get all characters AFTER first comma

Time:11-08

I'm trying to find a regex pattern to extract some names that apprear in a string after the first comma (David Peter Richard) below.

Example string: PALMER, David Peter Richard

I came across this thread that successfully extracts the name before, but require all the names after the comma.

I've tried to modify the ^.*?(?=,), but not having any joy. Needs to be JavaScript Regex and capture groups are not supported in the platform i'm using (Bubble)

Any help appreciated, thanks a lot!

I tried this: (?<=,)[^,]

Which seems to work on Desktop, however on a wrapped mobile app, it doesn't seem to work.

Similarly for the Name before, I was using ^[^,] and experiencing the same issue, but when I use the pattern in the ^.*?(?=,) it works fine.

So now I just need the pattern to be adjusted for the names after.

CodePudding user response:

On JavaScript, I would suggest a simple string split:

var input = "PALMER, David Peter Richard";
var names = input.split(/,\s*/);
console.log(names);

CodePudding user response:

try to use this regex for the after comma string:

,\s?(.*)$

hope this helps.

  • Related