String between curly braces

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
kevin007
Posts: 40
Joined: Mon Sep 21, 2015 7:46 am

String between curly braces

Post by kevin007 » Mon May 30, 2016 6:57 am

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}
--
Thanks
Kevin

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: String between curly braces

Post by Thierry » Mon May 30, 2016 9:04 am

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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

kevin007
Posts: 40
Joined: Mon Sep 21, 2015 7:46 am

Re: String between curly braces

Post by kevin007 » Mon May 30, 2016 9:16 am

@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 :(
--
Thanks
Kevin

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: String between curly braces

Post by Thierry » Mon May 30, 2016 9:30 am

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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

kevin007
Posts: 40
Joined: Mon Sep 21, 2015 7:46 am

Re: String between curly braces

Post by kevin007 » Wed Jun 01, 2016 7:13 am

@Thierry

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

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: String between curly braces

Post by Thierry » Wed Jun 01, 2016 8:37 am

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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: String between curly braces

Post by dunbarx » Wed Jun 01, 2016 3:03 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: String between curly braces

Post by jacque » Thu Jun 02, 2016 3:49 pm

Are you trying to decode JSON? There are libraries for that.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply