且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Powershell 从字符串中获取数字

更新时间:2023-02-19 12:40:39

使用正则表达式很简单:

This is simple to do with a regex:

 ('jsmit123456') -replace '\D+(\d+)','$1'

 123456

\D+ = 所有非数字,\d+ = 后面的所有数字.

\D+ = all the non-digits, \d+ = all the digits that follow.

 $studentid = $object.SAMAccountName -replace '\D+(\d+)','$1'