Jump to content

Recommended Posts

Posted (edited)

Referring to following coding, I would like to know on how to use loop to repeat searching matched word until the end of file.
 

$Source = Get-Content 'C:\Source.txt'
$name = [regex]::match($Source, '"name":"(.*?)"').Groups[1].Value
Write-Host "$name"

Does anyone have any suggestions?
Thanks in advance for any suggestions

 

C:\Source.txt contains following text

"name":"ABC" Go to School by Bus"name":"XYZ" Go to Library for reading

It should display following text

ABC

XYZ

Edited by oemript
Posted

Referring to following coding, I would like to know on how to use loop to repeat searching matched word until the end of file.
 

$Source = Get-Content 'C:\Source.txt'
$name = [regex]::match($Source, '"name":"(.*?)"').Groups[1].Value
Write-Host "$name"

Does anyone have any suggestions?
Thanks in advance for any suggestions

 

C:\Source.txt contains following text

"name":"ABC" Go to School by Bus"name":"XYZ" Go to Library for reading

It should display following text

ABC

XYZ

  • Moderators
Posted (edited)

Moved to a more appropriate sub-forum.

Edit: And Merged threads - you have been around long enough to know to stick to one post.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

You could do this.

 

$fileContent = [IO.File]::ReadAllText("C:\Users\You\Desktop\Test.txt")

$matches=[regex]::Matches($fileContent,'"name":"(.*?)"')


For ($i=0; $i -lt $matches.Count; $i++) {
  Write-Host $matches[$i].Groups[1].Value
}


Saludos

  • 2 weeks later...
Posted (edited)
On 1/1/2018 at 0:57 AM, Danyfirex said:

You could do this.

 


$fileContent = [IO.File]::ReadAllText("C:\Users\You\Desktop\Test.txt")

$matches=[regex]::Matches($fileContent,'"name":"(.*?)"')


For ($i=0; $i -lt $matches.Count; $i++) {
  Write-Host $matches[$i].Groups[1].Value
}


Saludos

Thank you very much for suggestions (^v^)

I would like to know on how to set the matching condition in order to retrieve 1 year as return into $match as shown below

$matches=[regex]::Matches($fileContent,'????(.*?)????')

Given : skdk kjn kjd<div class="c-time__value">            1        </div>        <div class="c-time__unit">            year        </div> jkdhjfknkjkjd

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

 

Edited by oemript

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...