Search code examples
regexnintex-workflow

RegEx to extract Date from time


I have the following date & time and looking to convert it to a simple digit using RegEx

What I have: 2017-11-02T04:00:00Z

What I want to convert it to: 20171102 (including leading zeros of months/dates)

Is this possible with RegEx? Was able to only get '2017-' after hours of work using '^(.*?)-'

Seems harder and harder, any helping hand is much appreciated

Edit: Showing where I am trying this. I am trying to do this on Nintex for SharePoint. But prior to that, I am using www.regEx101.com to validate

enter image description here

enter image description here


Solution

  • Use the following regex with the Replace template:

    ^(\d{4})-(\d{2})-(\d{2}).*
    

    and provide

    $1$2$3
    

    as the replacement pattern.

    Details

    • ^ - start of string
    • (\d{4}) - Group 1 (later referenced to with $1 backreference from the replacement pattern): four digits
    • - - a hyphen
    • (\d{2}) - Group 1 (later referenced to with $2 backreference from the replacement pattern): two digits
    • - - a hyphen
    • (\d{2}) - Group 3 (later referenced to with $3 backreference from the replacement pattern): two digits
    • .* - the rest of the string.

    See the regex demo.

    enter image description here