Jump to content

help with regex


Luigi
 Share

Recommended Posts

Greetings,

Someone can help-me with regex?

 

#include <StringConstants.au3>

Global $STRUCT1 = "Struct;char host[128];char sudo[128];char user[128];char pass[128];char path[256];char cmd[128];int code;EndStruct"

Global $regex = "[^,;]+"
;~  $regex = "^[.*?;|;.*:]"

Global $aStruct = StringRegExp($STRUCT1, $regex, $STR_REGEXPARRAYGLOBALMATCH)
_ArrayDisplay( $aStruct )

I want extract an array with:

char,host,128
char,sudo,128
char,user,128
char,pass,128
char,path,256
char,cmd,128
int,code,

Best regards.

Visit my repository

Link to comment
Share on other sites

  • 2 weeks later...

also non-regex fun and 2D arrays

#include<array.au3>

local $a[0][3]

Global $STRUCT1 = "Struct;char host[128];char sudo[128];char user[128];char pass[128];char path[256];char cmd[128];int code;EndStruct"

_ArrayAdd($a , StringReplace(StringReplace(StringReplace(StringReplace(StringReplace($STRUCT1 , ";EndStruct" , "" , 1) , "Struct;" , "" , 1) , "]" , "") , " " , ",") , "[" , ",") , 0 , "," , ";")

_ArrayDisplay($a)

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

smile.gif

#include<array.au3>

local $a[0][3]

Global $STRUCT1 = "Struct;char host[128];char sudo[128];char user[128];char pass[128];char path[256];char cmd[128];int code;EndStruct"

_ArrayAdd($a , StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($STRUCT1, ';?(End)?Struct;?', ""), '\]?;', @crlf) , '[ \[]', "|") )

_ArrayDisplay($a)

Edit
The new smileys are *awful*

Edited by mikell
Link to comment
Share on other sites

let the skinning begin!

#include<array.au3>

Global $STRUCT1 = "Struct;char host[128];char sudo[128];char user[128];char pass[128];char path[256];char cmd[128];int code;EndStruct"

_ArrayDisplay(stringsplit(_ArrayToString(StringSplit(stringtrimright($STRUCT1 , 10) , ";[] " , 2) , "," , 1) , ",," , 3))

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

half the ops, but the result has a bonus linefeed at the beginning...

Global $STRUCT1 = "Struct;char host[128];char sudo[128];char user[128];char pass[128];char path[256];char cmd[128];int code;EndStruct"

MsgBox(0, '' , StringRegExpReplace(StringRegExpReplace($STRUCT1 , "[\[\] ]" , ",") , "(Struct;|,;|;EndStruct)" , @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...