I'm trying to test user input that doesn't begin with or end in spaces, note that I am not trying to return the match.
I am aiming for a JavaScript-less solution so that the website can be used on web browsers like “Brave,” or used by users that activate a JavaScript blocker like “NoScript.”
It is impossible for my client to input a tab, newline, or other space like character.
The input is on 1 line, multiline is irrelevant.
I am allowing spaces within the input, just not at the beginning or end.
Examples of what should work:
“lorem ipsum”
“lorem ipsum dolor”
Examples of what should fail:
“ lorem ipsum ”
“abc ”
I'm pretty sure I'll need a negative lookbehind and lookahead, but I still haven't found a solution.
Some failed Regular Expressions I've come up with so far, while using regexr.com:
^(?<=[^ ]+).+(?=[^ ]+)$
^(?<! +)[ \w]+(?! +)$
^(?<! +)[^ ]+(?! +)$
^ {0}.+ {0}$
^([^ ]*).+([^ ]*)$
^\S*$