What is return character in regex?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
What is return character in regex?
I have three fields, and using the following script:
put the replacetext (field "text", field "find", field "replace") into field "text"
Not able to match a return character in field "text". I have tried the obvious \r. Help please?
put the replacetext (field "text", field "find", field "replace") into field "text"
Not able to match a return character in field "text". I have tried the obvious \r. Help please?
Kaveh
Re: What is return character in regex?
Kaveh-
regex by default doesn't deal with multiple lines. You need to give it the multi-line option (?s)
will do the trick.
regex by default doesn't deal with multiple lines. You need to give it the multi-line option (?s)
Code: Select all
put replacetext (field "text", "(?s) & "field "find" & "\s", field "replace") into field "text"
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: What is return character in regex?
Great. Thank you Mark. Can you give me a pointer to where I can find full documentation for livecode Regex?
Kaveh
Re: What is return character in regex?
LiveCode uses the standard pcre library, so any regex documentation should work.
But regex structures can get pretty complicated quickly.
Your best bet would probably be to try one of the many online regex testers and fiddle with things until it works.
Or try querying stackoverflow for particular questions.
But regex structures can get pretty complicated quickly.
Your best bet would probably be to try one of the many online regex testers and fiddle with things until it works.
Or try querying stackoverflow for particular questions.
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: What is return character in regex?
OK Mark. Good to know it is standard regex. But I thought the code you gave me was not standard. I will try a few things, then bother you again.
I am reasonably familiar with regex so hopefully that is not a problem. I just want to use what I did before in text editor, but in LiveCode with the obvious advantages.
By the way last time I looked I think there was no regex "look-ahead" implemented. I will try again.
I am reasonably familiar with regex so hopefully that is not a problem. I just want to use what I did before in text editor, but in LiveCode with the obvious advantages.
By the way last time I looked I think there was no regex "look-ahead" implemented. I will try again.
Kaveh
Re: What is return character in regex?
OK Mark. Good to know it is standard regex. But I thought the code you gave me was not standard. I will try a few things, then bother you again.
I am reasonably familiar with regex so hopefully that is not a problem. I just want to use what I did before in text editor, but in LiveCode with the obvious advantages.
By the way last time I looked I think there was no regex "look-ahead" implemented. I will try again.
I am reasonably familiar with regex so hopefully that is not a problem. I just want to use what I did before in text editor, but in LiveCode with the obvious advantages.
By the way last time I looked I think there was no regex "look-ahead" implemented. I will try again.
Kaveh
Re: What is return character in regex?
OK. I must be missing something really obvious. I have a field "text" with
I want to replace multiple returns with a single return. So I use:
but I get a result of
How can I insert a return character in the replacement text? I have tried \s etc. Is there a modifier to allow special chars to be inserted and if so where do I put that modifier?
Code: Select all
one
two
three
Code: Select all
put replacetext(fld "text", "\v+", "\r")
Code: Select all
one\rtwo\rthree
Kaveh
Re: What is return character in regex?
The only parameter that uses regex is the second one that supplies the actual regular expression. The first and third use normal LiveCode syntax. The LiveCode constant for a return character is the word "return" or "cr". Use one of those as the last parameter, without quotes since they are constants.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: What is return character in regex?
Kaveh-
What Jacque said. What you're trying to do now is different from your original post, and regex won't apply for the replacement text.
What Jacque said. What you're trying to do now is different from your original post, and regex won't apply for the replacement text.
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: What is return character in regex?
Also try
Code: Select all
filter field "text" without empty
Re: What is return character in regex?
Hah! I was just about to post the same thing. Although in long form I'd actually use
So, Kaveh, maybe you should be more explicit about what you're trying to do here... if you just want to condense all multiple returns down to one then I'd use the filter approach. But if you just want to remove specific repeats then you'll probably want something more complex.
Code: Select all
lock screen
put field "test" into tVar
filter tVar without empty
put tVar into field "test"
unlock screen
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: What is return character in regex?
This is my favoritest thing.SparkOut wrote:Also tryCode: Select all
filter field "text" without empty
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: What is return character in regex?
Kinda like "focus on nothing", eh?
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: What is return character in regex?
Yeah. I'm easily amused.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com