Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Ruby Regex for string "and/or" as exact match

I am trying to figure out the Ruby Regex for the exact string "and/or". For example, let’s say I have a name variable that is "Elvin and/or Jafarli"

name = "Elvin and/or Jafarli"

and I want to split the name based on the string "and/or". How is that done in Ruby?
This is the final result I am looking for:

name.split(some_regex) results in ["Elvin", "Jafarli"]

** UPDATE **
This is the current regex that exists in the system

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

names.split(/ (?i)(?:and|or) /)

What I want to do is to update the regex to also split on exactly string match like "Elvin and/or Jafarli". With the suggestions below, there is no output

>Solution :

Add another alternative with |, and escape the delimiter:

names.split(/ (?i)(?:and|or|and\/or) /)

or use the alternative regex literal form:

names.split(%r{ (?i)(?:and|or|and/or) })
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading