Jump to content

StringRegExReplace in File.


Recommended Posts

  • 3 weeks later...
  • 3 weeks later...

Hi  @mikell Are I correct when use this script below for capture string 'D2596B055075' of path below.

$a = 'H:\01. PRODUCTION\01. NEW SHIPMENT\04-CASE RELATED AND NEWS AND BUSINESS\07-19-2017\Part C 16.00\D2596B055075\aaaaaaaaaa\66666666666666\6666666666666666666666'
; or
$a = 'H:\01. PRODUCTION\01. NEW SHIPMENT\04-CASE RELATED AND NEWS AND BUSINESS\07-19-2017\Part C 16.00\D2596B055075
$b = StringRegExpReplace($a, '(.*)\\(D.*?)(|\\(.*))', '$2')
ConsoleWrite($b)

 

Edited by tezhihi
Link to comment
Share on other sites

9 minutes ago, tezhihi said:

Hi  @mikell Are I correct when use this script below for capture string 'D2596B055075' of path below.

$a = 'H:\01. PRODUCTION\01. NEW SHIPMENT\04-CASE RELATED AND NEWS AND BUSINESS\07-19-2017\Part C 16.00\D2596B055075\aaaaaaaaaa\66666666666666\6666666666666666666666'
; or
$a = 'H:\01. PRODUCTION\01. NEW SHIPMENT\04-CASE RELATED AND NEWS AND BUSINESS\07-19-2017\Part C 16.00\D2596B055075
$b = StringRegExpReplace($a, '(.*)\\(D.*?)(|\\(.*))', '$2')
ConsoleWrite($b)

 

use: 
 

_PathSplit()

 

Regards,
 

Link to comment
Share on other sites

nop
 

#include <Array.au3>
#include <File.au3>

Local $sFilePath='H:\01. PRODUCTION\01. NEW SHIPMENT\04-CASE RELATED AND NEWS AND BUSINESS\07-19-2017\Part C 16.00\D2596B055075'

Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = ""
Local $aPathSplit = _PathSplit($sFilePath, $sDrive, $sDir, $sFileName, $sExtension)
_ArrayDisplay($aPathSplit, "_PathSplit of " & $sFilePath)

 

Regards,
 

Link to comment
Share on other sites

3 hours ago, Trong said:

nop
 

#include <Array.au3>
#include <File.au3>

Local $sFilePath='H:\01. PRODUCTION\01. NEW SHIPMENT\04-CASE RELATED AND NEWS AND BUSINESS\07-19-2017\Part C 16.00\D2596B055075'

Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = ""
Local $aPathSplit = _PathSplit($sFilePath, $sDrive, $sDir, $sFileName, $sExtension)
_ArrayDisplay($aPathSplit, "_PathSplit of " & $sFilePath)

 

I mean about catch only D2596B055075 not full file path @@. Find in string and replace and result is D2596B055075

Link to comment
Share on other sites

1 minute ago, tezhihi said:

I mean about catch only D2596B055075 not full file path @@. Find in string and replace and result is D2596B055075

Whatever!
 

Local $string = "Whatever! Something, somethinglt is D2596B055075 Whatever! Something, something"
Local $searchstring = "D2596B055075"
Local $replacestring = "Whatever!!!!!!!!!!!!!"


Local $newString = StringReplace($string, $searchstring, $replacestring)

ConsoleWrite($string & @CRLF)
ConsoleWrite($newString & @CRLF)

 

Regards,
 

Link to comment
Share on other sites

@tezhihi

The regex doesn't work because of the alternation in (|\\(.*))  : "match nothing or \\(.*)" . For the first string,  (D.*?) returns everything after D
If you remove the alternation it will work for the first but not for the second. And if you make the second part of the expression optional then it doesn't work for the first string again 

So assuming that the part you want always begins with a D, a correct way could be this

$b = StringRegExpReplace($a, '.*\\(D[^\\]+).*', '$1')

this expression matches "D and one or more non-backslash chars" (heeding the backslash just before the D)
:)
 

Edit
Trong, sometimes you have to guess a little what is the real question and so what should be a correct answer :D
i.e. the non-regex way

Local $b, $split = StringSplit($a, "\")
For $i = 2 to $split[0]
  If StringLeft($split[$i], 1) == "D" Then $b = $split[$i]
Next
msgbox(0,"", $b)

 

Edited by mikell
Link to comment
Share on other sites

27 minutes ago, mikell said:

Trong, sometimes you have to guess a little what is the real question and so what should be a correct answer :D
i.e. the non-regex way

Local $b, $split = StringSplit($a, "\")
For $i = 2 to $split[0]
  If StringLeft($split[$i], 1) == "D" Then $b = $split[$i]
Next
msgbox(0,"", $b)

 

Sorry I have a problem communicating!
And limited English proficiency, my friend is Google Translate.

Regards,
 

Link to comment
Share on other sites

1 minute ago, Trong said:

đù Người Việt
Tiếng Việt =>  English => Tiếng Việt thì khó hiểu bỏ mịa =]]

Tôi thấy ông vào comment buồn cười quá nên cố tình thôi. Tôi đang hỏi về regex mà :)) đơn giản là tách cái D2506 xxx kia ra thôi chứ cái pathsplit hay string bla bla ko ra đâu tại đường dẫn nó thay đổi linh tinh. Ok cảm ơn nhé 

Edited by tezhihi
Link to comment
Share on other sites

Những cái đó thì bạn phải nói rõ. Có cái gì,  cần cái gì và muốn kết quả thế nào thì người ta mới dễ giúp chứ!

Mà forum Việt nó không chào đón bạn à?  Chỗ đó nó cấm tôi, cấm mọi nơi lên nơi đây là nhà của tôi!

Regards,
 

Link to comment
Share on other sites

  • Developers

Ok guys... back to English please in open forum.  Just keep practicing it and you will soon master it. :)

Jos

 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 3 months later...

Hi @mikell,

 

Long time no make a question :(. I need to get some data from manifest.xml as blue highlight of image show below.

Highlight.png

So please check and provide me the correctness of my regex below:

Local $aLNI = StringRegExp($LNI, '.*guid="(.*?)"\soverrideConversionId.*', 1)
Local $aSource = StringRegExp($LNI, '.*source" name="(.*?)" md5sum.*', 1)
Local $Court = StringRegExp($LNI, '.*CLINV_code" value="(.*?)".*', 1)
Local $CharCount = StringRegExp($LNI, '.*estKeyCharCount" value="(.*?)".*', 1)

and if you can please provide me the way to use these regex in C#. Thanks you so much :D

 

Edited by tezhihi
Link to comment
Share on other sites

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
 Share

×
×
  • Create New...