What is return character in regex?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: What is return character in regex?

Post by kaveh1000 » Sun Jan 25, 2015 12:11 pm

Thanks all for the pointers, and I agree with Mark that I failed to define the problem clearly! So here it is. Please look at the attached screenshot. The button "Clean text" has the following script:

Code: Select all

   put fld "text" into tTheText
   repeat with i = 1 to the number of lines of field "find"
      put  replacetext (tTheText, line i of fld "find", line i of fld "replace") into tTheText
   end repeat
   put tTheText into field "final text"
   
So it is a kind of user friendly Perl script. Ideally I want to put standard PCRE text in the replace box, but I am happy to put LiveCode constants like "return" if no other way. (Actually, putting return in "replace" is not working with or without quotes. I am sure that is a newbie question!)

This is not the primary goal, but it would be nice to click a button when the script is working, and generate a Perl or Python script.

Thanks for the help so far and any further ideas appreciated.
Attachments
find.png
Kaveh

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: What is return character in regex?

Post by mwieder » Sun Jan 25, 2015 8:21 pm

Kaveh-

Try this:

Code: Select all

on mouseUp
  local tText
  local tReplace
  
  lock screen
  put fld "fldInitialText" into tText
  repeat with i = 1 to the number of lines of field "fldFind"
    put line i of field "fldReplace" into tReplace
    replace "\r" with return in tReplace
    put  replacetext (tText, line i of fld "fldFind", tReplace) into tText
  end repeat
  put tText into field "fldFinalText"
  unlock screen
end mouseUp
with field "fldFind":
(?s)\\item[\s]+
(?s)[\n]+\\begin{itemize}

and field "fldReplace":
\item
\r\begin{itemize}

Note: you seemed to want to use "\r" in the replacement string, but note that you could just as easily use "\n" with the appropriate change to the code.
Attachments
Kaveh.png

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: What is return character in regex?

Post by kaveh1000 » Sun Jan 25, 2015 8:48 pm

Wow. Thanks for spending the time in this Mark. :-) Next drink is on you. ;-)

I am going to look at this tomorrow, but quick question: can I put the (?s) in the script to keep the find lines clean? In fact, are you sure that is needed? I think for me the multiline search worked without the (?s)
Kaveh

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: What is return character in regex?

Post by mwieder » Sun Jan 25, 2015 9:45 pm

I'll leave the experimenting to you.
Shouldn't be any problem with moving the modifier string into the code. Nice catch - I didn't think of that.
I didn't try it without the modifiers - regex *normally* works with a single string, so a newline char ends the match attempt, but if it works it works.

Post Reply