-3

I have a text data like these event_date=2020-01-05 how to eliminate all characters except the two last digit/date with regex?

  • 2
    Why do it with a regexp? Just use a substring. – Barmar Jan 07 '20 at 07:49
  • The question doesn't appear to include any attempt at all to solve the problem. Please edit the question to show what you've tried, and show a specific roadblock you're running into with [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). For more information, please see [How to Ask](https://stackoverflow.com/help/how-to-ask). – Andreas Jan 07 '20 at 07:54
  • Which shell? That will open up more options if you are using for instance, bash. Otherwise a `sed 's/^.*-//'` will leave only the last two chars, as will the old `expr substr "event_date=2020-01-05" "$(($(expr length "event_date=2020-01-05") - 1))" "2"` as will `awk -F'-' '{print $NF}'` – David C. Rankin Jan 07 '20 at 07:54
  • Looks like you are looking to create a regex, but do not know where to get started. Please check [Reference - What does this regex mean](https://stackoverflow.com/questions/22937618) resource, it has plenty of hints. Also, refer to [Learning Regular Expressions](https://stackoverflow.com/a/2759417/3832970) post for some basic regex info. Once you get some expression ready and still have issues with the solution, please edit the question with the latest details and we'll be glad to help you fix the problem. – Wiktor Stribiżew Jan 07 '20 at 08:39

1 Answers1

0

Regex is about Search & Matching character, example : event_date=(?20[0-9]{2})-(?[0-9]{2})-(?[0-9]{2})

Group 'year' will get 2020 Group 'month' will get 01 Group 'day' will get 05

just use replace(vb) or str_replace(PHP)

Agus W
  • 1
  • 2