My goal is to validate a string to ensure it contains letters only between two '#' symbols.
For example:
#one# + #two#
- is considered a valid string
#one# two
- is not valid
#one# + half + #two#
- is also not a valid string (only #one# and #two# are valid sections)
The rule is that odd occurrences of '#' allow for entering letters, while even occurrences of '#' should close the space where letters can be written.
I have created a regex pattern that works for most cases, but I'm struggling with the last scenario.
Here is my current regex pattern:
/^[^a-zA-Z]*(#.+#)[^a-zA-Z]*$/g
I'm testing this pattern on the regex testing site
As a last resort, if regex is not sufficient, I may consider splitting the string on '#' and checking the remaining sections for letters in typescript.
Any thoughts on how to successfully validate this type of string? Thank you.