Jump to content

Recommended Posts

Posted (edited)

Hello everyone

Is it possible to define a variable using regular expressions (e.g. using back-references)?

I mean, if I have this text:
<p>Some text here</p>
and I use this regex pattern: (<p>)(.+?)(</p>)
along with this backreference pattern: $1$2$3
... is there a way to add only "Some text here" (i.e. $2) to a variable $foo?

Thanks

Samuel

 

 

 

Edited by leuce
Posted
#include <array.au3>
#include <MsgBoxConstants.au3>

Local $sInput = 'Some Text Here'
Local $sOutput = StringRegExpReplace($sInput, '(\w+)\s(\w+)\s(\w+)', '$3/$2/$1')
Local $sMsg = StringFormat("Input:\t%s\n\nOutput:\t%s", $sInput, $sOutput)
; Result String
MsgBox($MB_SYSTEMMODAL, "Result", $sMsg)

Local $aNewArray = StringSplit ( $sOutput, "/" )
; Result Array after StringSplit
_ArrayDisplay ( $aNewArray, "New Array" )

Local $sFoo = $aNewArray [1]
; Result String assigning $aNewArray [element 1] to $sFoo
Msgbox ($MB_SYSTEMMODAL, "Result", "$sFoo = " & $sFoo )

Perhaps using StringSplit ()

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...