0

so I have been trying to work out how to do an alternate regex match for a Positive Lookbehind in Javascript, I have been trying on and off for 3 days now with no luck, what I want to do works in PHP, but I NEED it to be Javascript.

here is a PHP example of what I want to do: https://regex101.com/r/YpMbI2/5

I usually try to work things out myself, but after 3 days, I kinda need some assistance :D

Thanks in advance for your help :D

MRVDOG
  • 1,717
  • 2
  • 13
  • 20
  • Just replace with `(^|\W)(\s?>)(.+)(?:\n|$)` and manipulate the groups later - what are trying to achieve in the end? Could you provide a minimal example: some input and expected output? – Wiktor Stribiżew Dec 14 '16 at 15:37
  • Javascript regex does not support lookbehind. – Kenneth K. Dec 14 '16 at 15:38
  • 2
    Possible duplicate of [javascript regex - look behind alternative?](http://stackoverflow.com/questions/7376238/javascript-regex-look-behind-alternative) – Rápli András Dec 14 '16 at 15:42
  • @KennethK. I know, this is why I'm asking for help :P I'm trying to figure out a way to do my matches without them – MRVDOG Dec 14 '16 at 15:42
  • Ah. I wasn't sure if by "alternate" you meant that or the vertical bars that you have in your pattern. – Kenneth K. Dec 14 '16 at 15:51
  • @WiktorStribiżew I am coding a BetterDiscord plugin and trying to code in a way to add quotes using `>text`, the example link kinda shows what I'm trying to match and not match, it's kinda hard to show with screenshots – MRVDOG Dec 14 '16 at 15:51
  • "To add quotes" means you need to *replace* text. You do not even need a lookbehind here. Just capturing. So, if you need help, please add some simple but comprehensive sample input and expected output *into the question body*. Else, you are the only person who can answer this question. – Wiktor Stribiżew Dec 14 '16 at 15:56

1 Answers1

1

You can use

(?:^|\W)\s?>(.+)(?:\n|$)

since it seems that only the capture group seems to interest you.

Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142