Jump to content

How to detect know and unknow strings with StringRegExp?


 Share

Recommended Posts

This example matches the first two occurrences of "85C0741A68??????1068??????1068??????108BC8E8",  then, only on the third occurrence, replaces "85C0741A68" in "85C0741A68??????1068??????1068??????108BC8E8" with "85C0EB1A68".

You should be able to figure out the RE pattern by studying the StringRegExp and StringRegExpReplace functions in the Autoit  help file.

#include<array.au3>

$data = "abc85C0741A68??????1068??????1068??????108BC8E8w " & _
        "def85C0741A68??????1068??????1068??????108BC8E8x " & _
        "gfi85C0741A68??????1068??????1068??????108BC8E8y " & _
        "jkl85C0741A68??????1068??????1068??????108BC8E8z " & _
        "85C0741A68??????1068??????1068??????108BC8E8 " & _
        "85C0741A68??????1068??????1068??????108BC8E8 " & _
        "85C0741A68??????1068??????1068??????108BC8E8 " & _
        "85C0741A68??????1068??????1068??????108BC8E8 " & _
        "85C0741A68??????1068??????1068??????108BC8E8 " & _
        "85C0741A68??????1068??????1068??????108BC8E8 " & _
        "85C0741A68??????1068??????1068??????108BC8E8 " & _
        "85C0741A68??????1068??????1068??????108BC8E8 " & _
        "85C0741A68??????1068??????1068??????108BC8E8 " & _
        "85C0741A68??????1068??????1068??????108BC8E8 "


;$p = StringRegExpReplace($data, "^.*?(85C0741A68.{6}1068.{6}1068.{6}108BC8E8.*?85C0741A68.{6}1068.{6}1068.{6}108BC8E8.*?)(85C0741A68)(.{6}1068.{6}1068.{6}108BC8E8)", "${1}85C0EB1A68${3}")

; Or

Local $iReplaceOccurrenceNumber = 3

$p = StringRegExpReplace($data, "^(.*?(?:85C0741A68.{6}1068.{6}1068.{6}108BC8E8.*?){" & $iReplaceOccurrenceNumber - 1 & "})(85C0741A68)(.{6}1068.{6}1068.{6}108BC8E8)", "${1}85C0EB1A68${3}")
ConsoleWrite($p & @LF)

 

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

  • Recently Browsing   0 members

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