I'm trying to create a regular expression that will match any given string (text or whitespace) inside of arbitrary, optional whitespace. The string itself could have whitespace in it;
I'm just trying to cut white space of the beginning and end, if it exists.
Example strings:
- one
- t
- three
- four
- five
Expected output:
- one
- t
- three
- four
- five
I've been testing on regextester.com but have so far haven't been able to get it quite right.
[^\s][\w\W]*[^\s] will match cases 1, 3, 4, and 5, but it fails for single-character strings.
[^\s]*[\w\W]*[^\s] gets 1, 2, and 4, but it includes the leading whitespace from 3 and 5.
Is there a regular expression can handle this task? I'd also settle for using option 2 above and then trimming off the leading whitespace afterwards, but not sure how to do that.
 
     
     
    