How to create a regex that will match an arbitrary sequence of spaces and tabs

前端 未结 4 1010
一生所求
一生所求 2020-12-29 01:33

Could anyone help me to assemble a pattern that matches an arbitrary sequence of spaces and tabs?

相关标签:
4条回答
  • 2020-12-29 02:13
    [ \t]+

    will match arbitrary sequences (e.g., spaces followed by tabs followed by more spaces ...).

    0 讨论(0)
  • 2020-12-29 02:15

    ( |\t)+ will match a sequence of one or more spaces or tabs, is that what you're looking for ?

    0 讨论(0)
  • 2020-12-29 02:15

    To piggy-back on @Justin Morgan's answer, note that according to https://regex101.com/, \s+ is equal to [\r\n\t\f\v ]+.

    Therefore, if your system doesn't support the \s+ (or \s*) construct, use [\r\n\t\f\v ] in place of the \s part instead.

    0 讨论(0)
  • 2020-12-29 02:21

    \s+ should capture all whitespace, including spaces, tabs, carriage returns, and some weird whitespace characters. Use \s* if you want it to be optional.

    0 讨论(0)
提交回复
热议问题