How can I use regex to split on this `;` seperator? `Individual Portraits (5x7) (1); Individual Portrait (8x10) (1); Digital Download (Individual) (1)`

Asked on 2025-06-30

1 search

To split a string on the ; separator using regex, you can use the following regular expression pattern in a programming language that supports regex, such as Python or JavaScript:

\s*;\s*

This pattern matches a semicolon (;) surrounded by any amount of whitespace (including none). This ensures that any spaces around the semicolon are not included in the resulting split strings.

Here's an example of how you might use this in Python:

import re

text = "Individual Portraits (5x7) (1); Individual Portrait (8x10) (1); Digital Download (Individual) (1)"
result = re.split(r'\s*;\s*', text)

print(result)

This will output:

['Individual Portraits (5x7) (1)', 'Individual Portrait (8x10) (1)', 'Digital Download (Individual) (1)']

This approach ensures that the split operation is clean and does not include any leading or trailing spaces in the resulting list of strings.