简体   繁体   中英

Regular Expression Replace One Character with Space

I have a timestamp in a AWS log file with this format: 2021-04-04T12:21:29Z

This Regular Expression will capture the timestamp into three groups:

(?<utcDate>[0-9]{4}-[0-9]{2}-[0-9]{2})(?:T)(?<utcTime>[0-9]{2}:[0-9]{2}:[0-9]{2})

Outputting: 2021-04-04T12:21:29

I'm trying to replace the T with a space to create a valid timestamp format to import into a SQL timestamp column via AWS Athena. I'm already using date_parse concatenating the two utcDate and utcTime groups into a timestamp in my select statement. But I want to have a timestamp in my table so I can query on the timestamp in my where clause.

When I make the above regular expression into one group comprised of subgroups, the T still gets returned even though it's defined in a Non-Capture Group. Is it possible to match the one character T and replace it with a space?

Thanks for any help.

If what you want to do is replace the T with a space: replace(column_name, 'T', ' ') . If you want a TIMESTAMP from your ISO 8601 string: from_iso8601_timestamp(column_name) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM