-1

How can I get the string before the character "|" using regular expressions?

For example, I have "data1|data2" and I want to return "data1".

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Purnima Naik
  • 2,393
  • 5
  • 17
  • 25
  • 1
    What language? What have you tried? – chris85 May 18 '17 at 15:59
  • You have `data1|data2`, I have `|data1|data2` and we both want `data1` because we see that _data1_ is what is needed. So, what does the pipe have to do with it ?? –  May 18 '17 at 16:22

1 Answers1

-1

You want this regex: ^.+?(?=\|)

  • ^ beginning of line
  • .+? one or more characters, as few as possible
  • (?=) forward look ahead assertion; make sure you can see the enclosed pattern
  • \| a literal | character
Phrogz
  • 296,393
  • 112
  • 651
  • 745