Jump to content

RegExp help please


dmob
 Share

Recommended Posts

I have a string and need to extract, process and finally replace all substrings between, and including the { }
I was hoping to use RegEx but cannot figure out how repeat the search pattern.

#include <Array.au3>

Local $sPatt = "({(.*)}" ; "(?:{(.*)})"
Local $sString = "{A.Item}, R{B.Some} {B.Other} text string {C.Date} {C.Item}{C.Thing}"
Local $aArray = StringRegExp($sString, $sPatt, 3)

_ArrayDisplay($aArray)

My goal is an array with:
{A.Item}
{B.Some}
{B.Other}
{C.Date}
{C.Item}
{C.Thing}

Edited by dmob
Link to comment
Share on other sites

@dmob : imho you were nearly there :

#include <Array.au3>

$txt = "{A.Item}, R{B.Some} {B.Other} text string {C.Date} {C.Item}{C.Thing}"

$arr1 = StringRegExp($txt,"({[^}]*})", 3)
_ArrayDisplay($arr1, "Nine's negated way")

$arr2 = StringRegExp($txt,"(?U)({.*})", 3)
_ArrayDisplay($arr2, "Lazy way #1")

$arr3 = StringRegExp($txt,"({.*?})", 3)
_ArrayDisplay($arr3, "Lazy way #2")

 

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