Sign in to follow this  
Followers 0
Zedna

StringRegExp - two groups in any order

7 posts in this topic

#1 ·  Posted (edited)

I need to extract name and initial values from my string:

column=(type=number updatewhereclause=yes name=cpa_kniha dbname="cpa_kniha" initial="getdate()" values="1/0")

but sometimes it can be in differrent order (first initial and second name):

column=(type=number updatewhereclause=yes initial="getdate()" name=cpa_kniha dbname="cpa_kniha" values="1/0")

I have done it by two calls of StringRegExp():

$ret = StringRegExp($line, '(?i)name=(.*?)\x20(.*?)initial="(.*?)"', 3)
            If @Error = 2 Then  
                $ret = ' !!! CHYBA RegExp !!! pozice: ' & @extended
            ElseIf @Error = 0 Then  
                $ret = 'name=' & $ret[0] & ' initial=' & $ret[2]
            ElseIf @Error = 1 Then ; if not found (but is there), so they are in differrent order
                $ret = StringRegExp($line, '(?i)initial="(.*?)"(.*?)name=(.*?)\x20', 3)
                If @Error <> 0 Then     
                    $ret = ' !!! CHYBA RegExp !!! pozice: ' & @extended
                Else
                    $ret = 'name=' & $ret[2] & ' initial=' & $ret[0]
                EndIf
            EndIf
Edited by Zedna

Share this post


Link to post
Share on other sites



HI,

do you need it sorted or is this enough?

#include<Array.au3>
$str = 'column=(type=number updatewhereclause=yes name=cpa_kniha dbname="cpa_kniha" initial="getdate()" values="1/0")' & @CRLF & _
        'column=(type=number updatewhereclause=yes initial="getdate()" name=cpa_kniha dbname="cpa_kniha" values="1/0")'

$ret = StringRegExp($str, '(?<=name=).*?(?=dbname)|(?<=initial=").*?(?=")', 3)
_ArrayDisplay($ret)

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

HI,

do you need it sorted or is this enough?

#include<Array.au3>
$str = 'column=(type=number updatewhereclause=yes name=cpa_kniha dbname="cpa_kniha" initial="getdate()" values="1/0")' & @CRLF & _
        'column=(type=number updatewhereclause=yes initial="getdate()" name=cpa_kniha dbname="cpa_kniha" values="1/0")'

$ret = StringRegExp($str, '(?<=name=).*?(?=dbname)|(?<=initial=").*?(?=")', 3)
_ArrayDisplay($ret)oÝ÷ Ù*%¢xz¿ªê-y8ZK7Ý8Z·l·´Z½ê')bæò)Þ¦ºzË"(²íx"²z-çyÐn·*.®Ê%ºØ¨+'¢Úh²ÈëhºÇ¢¹mçºÇç­ën®wrn{"Ø^±©¢·^®èºÚn¶z&jØ^®Ø^º+uêè)éºÔzlÅ©©â7öh¶Ø§v¦y©Ýx­©_®¶¸§ kzÛ«çZ®¶²{h+p¢«¨¶ö«¹^²«¨¶Þ~çjgÚ'yú+x­©X¢êéjÛ^®x§~*ì¶X§z·­º¹Û©ý¶¬~*ì¶ö¥¹æ§u¸§ØöڲǢw^½©nz)ìyÊ'vX§z·­º¹Ûx­©m«»-½©ny©Ýnv¦{öڲǢw^½©nx-+,¢g¡£
h²Èëh²oy±!?Ûrn{©u¹Úè§Øöè)éºÙbç·¢©ò¢·^­»­Ê«¥«mz¹ëzX²é­ë,ºjmí«[u¹ÚïÛƵêÛ©ý´áz·¦ºË[zl¦zØhw­OvÇm:Ùø«²Û)iÇ~׫©
Edited by Zedna

Share this post


Link to post
Share on other sites

Hi,

I connot sort it or save into 2 arrays. :-(

#include<Array.au3>
$str = 'column=(type=number updatewhereclause=yes name=cpa_kniha dbname="cpa_kniha" initial="getdate()" values="1/0")' & @CRLF & _
        'column=(type=number updatewhereclause=yes initial="getdate()" name=cpa_kniha dbname="cpa_kniha" values="1/0")'

$ret = StringRegExp($str, '(?<= name=)\S+|(?<=initial=")[\w(\)]+', 3)
_ArrayDisplay($ret)

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This is my testing script:

On every StringRegExp only one line

Both results should return columns in the same order

$str = 'column=(type=number updatewhereclause=yes name=cpa_kniha dbname="cpa_kniha2" initial="getdate()" values="1/0")'

$ret = StringRegExp($str, '(?<=name=).*?(?=dbname)|(?<=initial=").*?(?=")', 3)
_ArrayDisplay($ret,'')

$str = 'column=(type=number updatewhereclause=yes initial="getdate()" name=cpa_kniha dbname="cpa_kniha" values="1/0")'

$ret = StringRegExp($str, '(?<=name=).*?(?=dbname)|(?<=initial=").*?(?=")', 3)
_ArrayDisplay($ret,'')
Edited by Zedna

Share this post


Link to post
Share on other sites

Hi,

just a little step forwards.

#include<Array.au3>
$str = 'column=(type=number updatewhereclause=yes name=cpa_kniha dbname="cpa_kniha" initial="getdate()" values="1/0")' & @CRLF & _
        'column=(type=number updatewhereclause=yes initial="getdate()" name=cpa_kniha dbname="cpa_kniha" values="1/0")'

$ret = StringRegExp($str, '/(name)=\"*([\w\(\)]+)\"*|(initial)=\"*([\w\(\)]+)\"*', 3)
_ArrayDisplay($ret, '')

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hi,

just a little step forwards.

#include<Array.au3>
$str = 'column=(type=number updatewhereclause=yes name=cpa_kniha dbname="cpa_kniha" initial="getdate()" values="1/0")' & @CRLF & _
        'column=(type=number updatewhereclause=yes initial="getdate()" name=cpa_kniha dbname="cpa_kniha" values="1/0")'

$ret = StringRegExp($str, '/(name)=\"*([\w\(\)]+)\"*|(initial)=\"*([\w\(\)]+)\"*', 3)
_ArrayDisplay($ret, '')

So long,

Mega

Thanks very much for assistance th.meger

This looks like it could be done.

It's close to final but result is bad:

post-6483-1180703396_thumb.png

I'm reg exp amater, so your patterns are too difficult for me to understand :)

Edited by Zedna

Share this post


Link to post
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
Sign in to follow this  
Followers 0