Match string with a multi-character limit

Viewed 21

I need to divide a list in alphabetical order.

I am using:

regexp_match("via",'^[A-G]')

for one segment, and

regexp_match("via",'^[H-Z]')

However, I need to cut the list halfway the "G" set of words, that is: to make "Galveston" fall in the first segment, and "Geneve" in the second.

How can I do this?

1 Answers

You can use the following two regexps:

^([A-F]|G[a-d])
^([H-Z]|G[e-z])

See regex demo #1 and regex demo #2.

Details

  • ^([A-F]|G[a-d]) - a letter from A to F, or G followed with a letter from a to d
  • ^([H-Z]|G[e-z]) - a letter from H to Z, or G followed with a letter from e to z.
Related