-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
  • 561,645
  • 34
  • 376
  • 476
Purnima Naik
  • 1,927
  • 5
  • 14
  • 23
  • 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
  • 284,740
  • 104
  • 634
  • 722