-1

How do I convert regex ^\d+.\d+.\d+ that matches pattern at the beginning of a string so that it trims everything after the match:

  1. 1234.123.1234 -> 1234.123.1234
  2. 1234.123.1234A -> 1234.123.1234
  3. 1234.123.1234-AB-> 1234.123.1234
  4. AB-1234.123.1234 -> not a match => AB-1234.123.1234
Liero
  • 22,266
  • 22
  • 120
  • 244
  • In general, `^(keep this).+` (or ``^(keep this)[\w\W]+`` multiline version) => `$1` (or `\1`). – Wiktor Stribiżew Jun 02 '22 at 07:56
  • I guess the (keep this) would be without the `^`, so it would be `^(\d+.\d+.\d+).+`. The brackets are only to group the matches, so it can be referenced using $1, right? Why do I need `.+` at the end, actually? – Liero Jun 02 '22 at 12:06
  • To consume the rest of the text that you want to remove. – Wiktor Stribiżew Jun 02 '22 at 12:11

0 Answers0