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

Google Sheets REGEXEXTRACT – Return to one column instead of two?

Using this formula returns values in two separate columns:

=ARRAYFORMULA(REGEXEXTRACT(A2:A, "(.+)\?|(.+)\"""))

How can I modify this to return everything in the same column? It works if I remove the parentheses (), but then the last character ? or " will appear at the end.

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

>Solution :

You can use

=ARRAYFORMULA(REGEXEXTRACT(A2:A, "(.+)[?""]"))

The pattern matches

  • (.+) – Group 1 (the group value is actually the return value here): one or more chars other than line break chars as many as possible
  • [?"] – a ? or " char.

Consider also the following variations:

=ARRAYFORMULA(REGEXEXTRACT(A2:A, "(.+?)[?""]"))
=ARRAYFORMULA(REGEXEXTRACT(A2:A, "([^?""]+)[?""]"))

The "(.+?)[?""]" variation matches up to the first occurrence of " or ?. The "([^?""]+)[?""]" also matches up to the first occurrence, but it can also match line break chars.

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