0

I want to take a multiline string such as

(DateofAdmission04 DateofDischarge04 PatDateOfBirthC
= record_keydate1 record_keydate2 dob).

And capture each of the words, to then be paired with it's associated word on the other side of the equals, ultimately to produce the result (in this example)

(DateofAdmission04 = record_keydate1 
DateofDischarge04 = record_keydate2 
PatDateOfBirthC = dob).

(or similar). Is this possible using regex? Ideally as a general solution that would work on lists of any length.

Moohan
  • 933
  • 1
  • 9
  • 27
  • See https://stackoverflow.com/questions/5018487/regular-expression-with-variable-number-of-groups and https://stackoverflow.com/questions/3172643/regex-repeated-capturing-groups – Wiktor Stribiżew Aug 13 '18 at 10:47
  • I don't know any regex flavor that can capture an indeterminate number of groups. Though, using C# regex flavor, each capture will be stacked (have a look at [System.Text.RegularExpressions.Capture](https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.capture.aspx)). But, as you only need pairing, using some split and join would probably be more readable and will do the job appropriately. – PJProudhon Aug 13 '18 at 11:37
  • Thanks, I'm using RegEx in notepad++ to rewrite some SPSS syntax. I don't know enough about Java, or C++ but I think I could probably write a bit of Python to use split and join as you suggested! – Moohan Aug 13 '18 at 12:12
  • [so] community is very active on Python. Feel free to ask if you're struggling with it. – PJProudhon Aug 13 '18 at 13:13

0 Answers0