Page 1 of 1

String between curly braces

Posted: Mon May 30, 2016 6:57 am
by kevin007
Hi All,

I want to find strings between curly brackets and store the string into a variable. :(
sample string:

{This is a
First
curly
bracket}

Re: String between curly braces

Posted: Mon May 30, 2016 9:04 am
by Thierry
kevin007 wrote: I want to find strings between curly brackets and store the string into a variable. :(
{This is a
First
curly
bracket}

Code: Select all

 matchText( aString, "(?s){(.+?)}", theMatch ) 
HTH,

Thierry

Re: String between curly braces

Posted: Mon May 30, 2016 9:16 am
by kevin007
@Thierry

It's only works when the string is in same line, if the part of the string is in another line it is not working :(

Re: String between curly braces

Posted: Mon May 30, 2016 9:30 am
by Thierry
kevin007 wrote:@Thierry

It's only works when the string is in same line, if the part of the string is in another line it is not working :(
Just tried out and it works as expected here :shock:

I test it on Mac with LC 8; but it shouldn't matter really.

any typo in your regex ?

Otherwise, make a simple stack with one field and one button.
put some text in the field and your code in the button and send me the stack.

Thierry

Re: String between curly braces

Posted: Wed Jun 01, 2016 7:13 am
by kevin007
@Thierry

In the following case How to change the code. :(
{{This is a}
First {\alpha}
curly {[$\beta$]}
bracket}

Re: String between curly braces

Posted: Wed Jun 01, 2016 8:37 am
by Thierry
kevin007 wrote: In the following case How to change the code. :(
Mmm, better stop using regex except if you are ready to learn them...

Instead try using:

Code: Select all

offset(charsToFind, stringToSearch [, charsToSkip])
See it in the dictionary, plus I believe there are some snippet of code
in this forum too.

Best,

Thierry

Re: String between curly braces

Posted: Wed Jun 01, 2016 3:03 pm
by dunbarx
Hi.

Regex, like dataGrids, are advanced tools, and should not be used by new users until they have a firm foundation in "ordinary" LiveCode. The attraction, especial with dataGrids, is easy to understand, but likely counterproductive, and even if one gets them working, I feel that it is putting the cart before the horse.

So do use "offset" as Thierry suggests. Though an intermediate-level function, at least it is "ordinary", in that it deals with variables and strings, the stuff of "ordinary" programming. It will tax you just a bit, as you try to isolate the text between the two different delimiting chars.

Craig Newman

Re: String between curly braces

Posted: Thu Jun 02, 2016 3:49 pm
by jacque
Are you trying to decode JSON? There are libraries for that.