-1

I have the following problem:

  • I want a regex to capture all characters in a paragraph that contains "#flashcard" and a string after a line break that starts with a "^" sign. E.g.,

lorem ipsum #flashcard ^4599993

  • However, the regex should ignore/exlude the sign "^" itself. The result should be, e.g.,

lorem ipsum #flashcard 4599993

  • I started with this regex

((?:[^\n][\n]?)+) #flashcard ?\n*((?:\n(?:^.{1,3}$|^.{4}(?<!<!--).*))+)

  • I tried all kinds of modifications but it always captured the "^" sign. E.g.,

^(?!\^)(.*?)#flashcard:(.*?),(.*?),(.*?)(?:^.{1,3}$|^.{4}(?<!<!--).*).

Solution: A modification of this regex

((?:[^\n][\n]?)+) #flashcard ?\n*((?:\n(?:^.{1,3}$|^.{4}(?<!<!--).*))+)

that ignores the "^" sign.

Thank you for any help & advise!

Val Chus
  • 11
  • 1
  • 1
    You can't cut a hole in the middle of a match. – Boann Jan 15 '23 at 14:26
  • 2
    `and a string after a line break that starts with a "^"`, where is the line break in `lorem ipsum #flashcard ^4599993` ? – SaSkY Jan 15 '23 at 14:45
  • You can use twice regex: First time regex : `/#flashcard.(.*?)$/i` Second time regex: `/\^/i` for select ^ only – ramin Jan 15 '23 at 14:52
  • try this : `#(.*?).\^|\d` – ramin Jan 15 '23 at 15:01
  • 1
    Besides the missing newline in the example data, in the patterns that you added to the question there seems to be more going on than just matching a `^` after `#flashcard` Can you add some real life examples of paragraphs and would you also accept multiple capturing groups as a match, or a second replacement over the matched string? – The fourth bird Jan 15 '23 at 16:23

1 Answers1

0

This could be your pattern: /^(.+?#flashcard )\^(.+?)$/

And then replace the matchings with: $1$2

Mehdi Abbassi
  • 627
  • 1
  • 7
  • 24