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.
On JavaScript, I would suggest a simple string split:
var input = "PALMER, David Peter Richard";
var names = input.split(/,\s*/);
console.log(names);
try to use this regex for the after comma string:
(?<=,\s)(.*)$
hope this helps.
Related
I'm using to validate the format of names in my rails applications. I need to update it so it doesn't accept something like mike.jones
current regex
/([A-Za-z ',.-]+)/
acceptable names
'Baxter',
'Doe de Sour Jr.',
'Smith-Brown',
"Mathias d'Arras",
"d'Arras",
'King, Jr.',
'Cotton III'
invalid names
'Baxter2',
'user#gmail',
'#michael',
'tina.fay'
The answer is a bit complicated when you need to account for periods that occur in the middle of valid names. According to your description, the rule seems to be that periods are fine as long as they aren't immediately followed by letters. This can be accomplished with regex lookahead:
^(?!.*\.\S)[A-Za-z ',.-]+$
demo: https://regex101.com/r/LkUl38/2
Then you just need to move the . to the end of your regex (and escape it) so that you still get people with Jr. at the end of their name:
/([A-Za-z ',-]+\.?)/
And it should work fine. Try it online!
There are some great resources online for learning Regex, if you're interested.
I tried to use regular expression to to capture both English and Chinese company name into two groups.
However I stuck at space issue, also if the line didn't contain chinese name, then i am unable to capture, can anyone help me to check what is the problem of my regular expression?
Link (https://regex101.com/r/VLwr7b/1/)
This will do:
^([^\p{Han}]*?)(?:\s+([\p{Han}].*))?$
Demo: https://regex101.com/r/VLwr7b/3
Hopefully this regex helps
https://regex101.com/r/VLwr7b/2
^([\s\S])*(.?[[:space:]])[(\[\p{Han}\/]?.+$ (new)
^([\s\S].*)[[:space:]]((?!\/)[\p{Han}\/].+)$ (old)
I think ultimately is due to the fact that your old regex wasn't catering to the availability of brackets hence, it was stuck.
I'm trying to write a regex for use in Calibre (python) to find ebooks that have the series name in brackets in the title. I have a custom column with the series name and title separated by a "~", for example:
"The Series~The Book Title (The Series)"
Best I can come up with finds anything with at least one letter from the series name in brackets in the title:
(.+)~.*[\(\1\)].*
I only want to find those that have the whole of the first part of the string in brackets at the end of the second part, it can contain extra info.
Thanks.
This works in Notepad++:
(.+)~[^\(]*\(\1\).*
I'm not sure it will work the same in python, but regexp processors are usually very similar, so try it out.
Your regex is pretty close, you can change a little your regex and have this:
(.+?)~.*[([]\1[)\]].*
Working demo
This will match strings like:
The Series~The Book Title (The Series)
The Series~The Book Title [The Series]
However, if you just want to match words with paretheses, then you can have:
(.+?)~.*[(]\1[)].*
or
(.+?)~.*\(\1\).*
Working demo
Thanks for the suggestions. They work perfectly in the python demo but for some unknown reason don't work in Calibre. Seems like one character is the most it will match from the capture group. Must be a limitation in the regex system Calibre uses.
I'm using the following line of regex which I found from this SO answer:
(?:[\w[a-z]-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.-]+[.??][a-z]{2,4}/)(?:[^\s()<>]+|(([^\s()<>]+|(([^\s()<>]+)))))+(?:(([^\s()<>]+|(([^\s()<>]+))))|[^\s`!()[]{};:'".,<>?«»“”‘’])
I am testing it on the following string:
"Quattro Amici in Concert Mar. 3, 2014. Long-time collaborators Lun Jiang, violin; Roberta Zalkind, viola; Pegsoon Whang, cello; and Karlyn Bond, piano, will perform works by Franz Joseph Haydn, Wolfgang Amadeus Mozart, Ludwig van Beethoven and Gabriel Faure. To purchase tickets visit westminstercollege.edu/culturalevents or call 801-832-2457. - See more at: http://entertainment.sltrib.com/events/view/quattro_amici_in_concert#sthash.QRsLXXiA.dpuf"
I'm simply attempting to extract urls from strings and based on a bunch of SO answers, I've found that regex is the recommended tool for that job. I'm not a regex expert (or even intermediate in my understanding), so I'm baffled by the empty strings my re.findall() keeps returning. I've stepped through the regex line using regex buddy and still no luck. Any help would be hugely appreciated.
I'm not sure that a big regex like that is entirely necessary - if you're just looking to get links, you could use a much simpler regex, like this:
/(https?:\/\/[\w\d\$-_\.\+!\*'\(\),\/#]+)/ig
According to RFC 1738, urls are only allowed to use the characters specified in the class above, so it should cover any valid url, without such a gigantic mess of a regex.
You can also use a tool like regexpal.com to validate regexes, which helps find issues. That said, I pasted your regex in there and it crashed chrome, so it may not be a great help for a beast like that :)
I am trying to make an if-then-else statement using RegEx. I want to match the text if it contains Monty and also contains Python. Also the text should get matched if Monty is not present in the text.
RegEx
(?(?=Monty)(?(?=Python).*|)|^.*).*$
Kindly help!
How about this:
(^(?!.*Monty(?!.*Python.*).*).*$|^.*Python.*Monty.*$)
This passes my tests, but let me know if it works for you.
I am not versed in lookahead regex but just tried to build the regex from what I understood from above description. Check the link to see if this is what you are trying to do.
try this instead
((?=Monty)((?=Python).*|)|^.*).*$