What regex to use for this

后端 未结 6 1080
心在旅途
心在旅途 2021-01-19 05:57

I\'m writing a regex that will find either

  • 1 or more dots . .. ... .... followed by a space or not followe
相关标签:
6条回答
  • 2021-01-19 06:41
    • To match one or more . characters followed by a space: /\.+ /
    • To match one or more . characters followed by nothing: /\.+$/
    • To match one or more ? characters followed by a space: /\?+ /
    • To match one or more ? characters followed by nothing: /\?+$/

    To match any of these patterns: /\.+ |\.+$|\?+ |\?+$/

    0 讨论(0)
  • 2021-01-19 06:42

    If you want to group each section...

    (\.+|\?+)( ?)(.+)

    0 讨论(0)
  • 2021-01-19 06:43

    For the dots, you can use the + thing, which specifies one or more occurrences of the preceding string. Also, you'd have to escape the . and the ?, as they have special meanings in regex:

    (\.+)$
    (\?+)$
    
    0 讨论(0)
  • 2021-01-19 06:46
    \.+ ?$
    \?+ ?$
    

    (you just need to escape a . or ? with a \ to match it literally, since those characters have special meanings in regular expressions.)

    Prefix either of these with ^ if you want to match lines containing only your pattern.

    0 讨论(0)
  • 2021-01-19 06:57

    If you need both in the same regex:

    (\.+|\?+)

    Or separate:

    (\.+)

    (\?+)

    And this answer needs to be 30 characters long to submit...

    0 讨论(0)
  • 2021-01-19 06:59

    You'd do something like the following

    (\.+|\?+)\s*
    
    0 讨论(0)
提交回复
热议问题