Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-mini-2025-04-14· OpenAIAi2 WildChat-4.8M (AI2)

regex starting line

  1. User

    regex starting line

  2. Assistant

    If you want a regular expression (regex) that matches the start of a line, you use the caret symbol ^.

    • ^ matches the position at the start of a line (or the start of the string if multiline mode is off).

    Example usage:

    • To match a line that starts with "Hello":

      ^Hello
      
    • To match the very start of the string only (if multiline mode is off):

      ^
      

    Multiline mode

    If you're working on a multiline string and want ^ to match the start of each line, enable multiline mode:

    • In many languages, this is done with the m flag.
    • For example, in JavaScript:
      const regex = /^Hello/m;
      

    Summary:

    • ^ = start of line/string
    • With m flag: start of each line within a multiline string

    Let me know if you want a regex for a specific language or context!