Re: [pcre-dev] PCRE2 String Concatenation regex

Kezdőlap
Üzenet törlése
Szerző: Zoltán Herczeg
Dátum:  
Címzett: Lisa Brinson
CC: pcre-dev
Tárgy: Re: [pcre-dev] PCRE2 String Concatenation regex
Hi,

this mailing list is about pcre library development, not general regular expression questions. Reddit is the right place for those tricky questions:

https://www.reddit.com/r/regex/

I try to answer your question though. Since the number of "string" tags are unknown, I would convert this in multiple steps.

- First, I would convert the initial tag, which looks like "string" +

s/((?:^|[^+ ]) *)("[^"]++") *\+/$1CONCAT($2,+/g

- Second, I would convert the +"string"+ parts

s/\+ *("[^"]++") *(?=\+)/, $1/g

- Third, convert the terminator +"strings" with a similar pattern.

Of course depending on the input you could create more complex patterns to fit your needs.

Regards,
Zoltan

Lisa Brinson <liz.brinz@???> írta:
>Hi,
>
>Please I wish to write a program that takes a string and recognizes the pattern “string a” + “string b” + "string c” + …. and converts that pattern to
>CONCAT("string a”, “string b”, “string c”, ….) using PCRE2 Library and I am completely stuck. So far, I managed to come up with the regex
>(“[a-z0-9A-Z_]*” + “[a-z0-9A-Z_]*”)* but I’m not sure if its correct though. Please can someone help me how to go about this problem?
>Waiting for your help. Code snippets will be highly appreciated.
>
>Thanks.
>Lisa