Me pēhea te ki te puranga te whakaingoa anō wahi o te ingoa kōnae i roto i te Windows PowerShell te whakamahi i regex?

I roto i tenei tauira, to tatou 6 kōnae raro ki te rā, me te ingoakōnae i raro:

Ingoa roa Aratau LastWriteTime
----                -------------         ------ ----
-he ----       10/06/2018     12:40              0 1 = 9.8.16 Bank Tauākī 298.67.pdf
-a ----       10/06/2018     12:40              0 2 = 9.9.16 Bank Tauākī 134.74.pdf
-a ----       10/06/2018     12:41              0 3 = 9.10.16 Bank Tauākī 123.43.pdf
-a ----       10/06/2018     12:41              0 4 = 9.11.16 Bank Tauākī 134.54.pdf
-a ----       10/06/2018     12:41              0 5 = 9.12.16 Bank Tauākī 157.98.pdf
-a ----       10/06/2018     12:41              0 6 = 9.1.17 Bank Tauākī 123.45.pdf

Here, Kei te ingoa kōnae te whakaari # i te timatanga, aru e =, aru e 'Tauākī Bank’ aru e te mutunga o te toenga tauākī.

Ko ēnei kōnae i roto i te Tauākī Kāri meka Credit me te kupu 'Bank’ Me ki kia whakakapia e 'Kāri Credit' te kupu. kia noho i te taua te toenga katoa o te ingoa kōnae.

I roto i te tikanga ki te whakatutuki i tenei, we will be using Windows PowerShell with Regex.

Hei whakarārangi i te tauākī katoa pēke, whakamahi tatou i te ls whakahau, Na putorino te putanga

ls | -newname ren {$_.name -replace('(.+)Bank(.+)','$ 1Credit Card $ 2')}

whakamahia te whakahau whakaingoa anō te i muri i te putorino ki whakaingoa i te kōnae. $_ Ko te ahanoa e mau te putanga i mua i te putorino, a kei te whakamahi tatou te ingoa taonga o te $_ ahanoa. -replace is used on strings in PowerShell, e whakakapi i te aho ki te string hou. -replace Ko te mahi e tango 2 tawhā. Ko te tawhā 1 ko te aho tawhito e hiahia ana tatou ki te whakakapi me te tawhā 2 ko te aho hou.

Hopu rōpū i roto i te regex taea pupuri tatou wahi o te aho. I roto i te regex, riro tetahi hoatu i roto i te reu e ki te whakamahi i muri. hei tauira,. (.+)Bank(.+) hopu tetahi i mua i a i muri i te pūāhua 'Bank'. Ka taea e tatou te whakamahi i enei wahi riro, mā te whakamahi i $ me te tau. hopu te reu 1 ki $1 me hopu te reu 2 ki $2 etc…

I roto i te tawhā 1, whakapūtā tatou te string tawhito e hiahia ana tatou ki te whakakapi, me i te wa ano hopu matou nga wahi o te aho e hiahia ana tatou ki te pupuri i (hopu). I roto i te tawhā 2, Ka whakamahia e te aho hou nga wahi horo e hiahia ana tatou ki te pupuri i, rite pai rite te aho hou iho hei tauira. '$1Credit Card$2'.

hua:

Aratau LastWrite Time Ingoa roa
----       ---------      ----            ------   ----
-he ----     10/06/2018     12:40              0 1 = 9.8.16 Kāri Credit 298.67.pdf Tauākī
-a ----     10/06/2018     12:40              0 2 = 9.9.16 Kāri Credit 134.74.pdf Tauākī
-a ----     10/06/2018     12:41              0 3 = 9.10.16 Kāri Credit Tauākī 123.43.pdf -a ----     10/06/2018     12:41              0 4 = 9.11.16 Kāri Credit Tauākī 134.54.pdf -a ----     10/06/2018     12:41              0 5 = 9.12.16 Kāri Credit Tauākī 157.98.pdf -a ----     10/06/2018     12:41              0 6 = 9.1.17 Kāri Credit 123.45.pdf Tauākī

Leave a Reply