0

Given this string:

"ManagerID='26a20e0e-23ba-4133-8bf4-e56f13115902' OR ManagerID='c86eede4-fdb4-45a8-88cf-4041c9d7a327'"

How can I transform it to this array:

["26a20e0e-23ba-4133-8bf4-e56f13115902", "c86eede4-fdb4-45a8-88cf-4041c9d7a327"]

Basically pulling out the OR and joining it. I can't seem to figure this one out.

1
  • 1
    str.scan(/(?<=ManagerID=').*?(?=')/) Commented Feb 13, 2018 at 21:17

2 Answers 2

1
string = "ManagerID='26a20e0e-23ba-4133-8bf4-e56f13115902' OR ManagerID='c86eede4-fdb4-45a8-88cf-4041c9d7a327'"

string.split(" OR ").map{ |x| x.gsub(/(^ManagerID='|'$)/, "") }
Sign up to request clarification or add additional context in comments.

Comments

0

ruby noob here, any way

 "ManagerID='26a20e0e-23ba-4133-8bf4-e56f13115902' OR
 ManagerID='c86eede4-fdb4-45a8-88cf-4041c9d7a327'".gsub(" OR ",'')

would produce =>"ManagerID='26a20e0e-23ba-4133-8bf4-e56f13115902' ManagerID='c86eede4-fdb4-45a8-88cf-4041c9d7a327'"

then split it by ManagerID=

    "ManagerID='26a20e0e-23ba-4133-8bf4-e56f13115902'
 ManagerID='c86eede4-fdb4-45a8-88cf-4041c9d7a327'".split("ManagerID=")

would produce => ['26a20e0e-23ba-4133-8bf4-e56f13115902', '26a20e0e-23ba-4133-8bf4-e56f13115902']

then simply join them by coma

['26a20e0e-23ba-4133-8bf4-e56f13115902', '26a20e0e-23ba-4133-8bf4-e56f13115902'].join(',')

this should give you the expected result, basically you can chain these operations into one statement, if my knowledge is correct, below code would give you the result.

 "ManagerID='26a20e0e-23ba-4133-8bf4-e56f13115902' OR ManagerID='c86eede4-fdb4-45a8-88cf-4041c9d7a327'".gsub(" OR ",'').split("ManagerID=").join(',')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.