i got a problem...
i want to find a way to check if something is NOT at the beginning of a new line... how should i do that?

Dani AI

Generated

You want to ensure the target is not at the start of a line. is on the right track (there must be something before it), but anchoring from the line start is brittle. A clearer approach is to assert that the character immediately before your pattern exists and is not a newline.

Modern JS (ES2018+): use a fixed-width lookbehind that requires one non-newline character before the pattern.

(?<=[^\r\n])yourPattern

This fails at the start of the string and right after any CR or LF, so it guarantees the match is not at the beginning of a line. See for details and compatibility notes.

Fallbacks for older engines (no lookbehind): either process text line-by-line or capture the preceding character and restore it in replacements. Two simple options:

  • Split on lines and test each line (most robust for complex logic).
  • Use a capture for the preceding non-newline char and keep it when replacing, e.g. replace ([^\r\n])(yourPattern) with $1....

Also be mindful of CRLF (\r\n) vs LF, and check browser/engine support if you rely on lookbehind. For how ^ and $ behave per-line, see the RegExp multiline flag documentation at .

If it is not at the beginning of the line, then there is at least one character in front of it. So, start with ^.+

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.