如何使用perl regex提取子字符串以进行跟踪?
Input: firstString123456lastString
Output: firstString
Input: first$String 123456 last@String
Output: first$String
类似于
的东西echo "firstString123456lastString" | sed -e "s|\([a-z]*\)[0-9].*|\1|"
答案 0 :(得分:1)
通过sed,
$ echo 'firstString123456lastString' | sed 's/^\([^0-9 ]*\).*/\1/'
firstString
$ echo 'first$String 123456 last@String' | sed 's/^\([^0-9 ]*\).*/\1/'
first$String
<强>解释强>
^
断言我们刚开始。[^0-9 ]*
否定字符类,匹配任何字符但不包含数字或空格零次或多次。([^0-9 ]*)
匹配的字符由组索引1捕获。答案 1 :(得分:0)
DECLARE @Schedule nvarchar (255) = '12/16/2015 7:51 PM'
DECLARE @Datetime DATETIME
DECLARE @NormalFormatDateTime VARCHAR(MAX)
set @NormalFormatDateTime =(select SUBSTRING(@Schedule,0,3) + '/' + SUBSTRING(@Schedule,4,2) + '/' + SUBSTRING(@Schedule,7,4) + ' ' + SUBSTRING(@Schedule,12,1) +':'+SUBSTRING(@Schedule,14,2))
SET @Datetime = CONVERT(VARCHAR(10), CONVERT(DATETIME, @NormalFormatDateTime),103) + ' ' + CONVERT(VARCHAR(8), CONVERT(DATETIME, @NormalFormatDateTime),108)