Regex help?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Regex help?
I'm trying to figure out why this doesn't work.
put replaceText(convText, "\$([a-z]*)=(\"[a-z]*\");", "ding")
I'm getting this error: compilation error at line 6 (Function: separator is not a ',') near "[", char 30
It doesn't seem to want to escape the " with \ and I don't know why, everything I've read says that's how to do it..
put replaceText(convText, "\$([a-z]*)=(\"[a-z]*\");", "ding")
I'm getting this error: compilation error at line 6 (Function: separator is not a ',') near "[", char 30
It doesn't seem to want to escape the " with \ and I don't know why, everything I've read says that's how to do it..
Marcus
Re: Regex help?
Hi tetranos,trenatos wrote:I'm trying to figure out why this doesn't work.
everything I've read says that's how to do it..
You didn't read one of my old post

Your regex looks good!
The problem is LC compiler which is not happy with some backslash

Put your regex in a custom prop or in a field, and it should work.
(I didn't check it..)
regards,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Regex help?
Hi Thierry,
You mean like this? put replaceText(convText, field "regField", "ding")
It's not working either, though no errors.
The issue is the LC compiler? :/
I'll sound like an ass but.. shouldn't something like that work in version 6.x? I mean, escaping characters is kind of common in regex.
You mean like this? put replaceText(convText, field "regField", "ding")
It's not working either, though no errors.
The issue is the LC compiler? :/
I'll sound like an ass but.. shouldn't something like that work in version 6.x? I mean, escaping characters is kind of common in regex.
Marcus
Re: Regex help?
Yes.trenatos wrote:Hi Thierry,
You mean like this? put replaceText(convText, field "regField", "ding")
IF you like you can send me some text you want to match..trenatos wrote: It's not working either, though no errors.
That's nothing to do with regex; try this:trenatos wrote:The issue is the LC compiler? :/
I'll sound like an ass but.. shouldn't something like that work in version 6.x? I mean,
escaping characters is kind of common in regex.
Code: Select all
put "1234" into x
put "12\z34" into x
put "12\"34" into x
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Regex help?
Sure, thanks for taking a look 
$color="red";
Grabs everything except the $ and ; for the replace (Dynamic interpretation of PHP variables)
Sorry I should have clarified, I'm not blaming the Regex implementation but the compiler.
I've had other issues with both the compiler and IDE (Like Undo not working, tabs becoming "stuck", slowing down to syrup over time, etc.)
When LC works, it's absolutely GREAT, seriously, but the "little quirks" is starting to get to me.

$color="red";
Grabs everything except the $ and ; for the replace (Dynamic interpretation of PHP variables)
Sorry I should have clarified, I'm not blaming the Regex implementation but the compiler.
I've had other issues with both the compiler and IDE (Like Undo not working, tabs becoming "stuck", slowing down to syrup over time, etc.)
When LC works, it's absolutely GREAT, seriously, but the "little quirks" is starting to get to me.
Marcus
Re: Regex help?
Actually, even this should work at least for testing: put replaceText(convText,"\$(.*);", "blabla")
But nope. It doesn't throw an error, but it also doesn't match $color="red"; in the source text.
But nope. It doesn't throw an error, but it also doesn't match $color="red"; in the source text.
Marcus
Re: Regex help?
trenatos wrote: $color="red";
Grabs everything except the $ and ; for the replace (Dynamic interpretation of PHP variables)
Code: Select all
fld 1: \$[a-z]*=\"[a-z]*\";
put replaceText( fld 2, fld 1, "$ding;")
Unfortunately, this is useless with the replaceText() LC function.
Check in LC Engine forum to see what I wanted to implement

Back to your example, you could write something like that:
Code: Select all
fld 1: \$([a-z]*=\"[a-z]*\");
get matchText( fld 2, fld 1, gotIt)
get matchChunck( fld 2, fld 1, gotIt1,gotIt2)
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Regex help?
Your first example replaced the string with $ding, but you're saying that () won't work.
And I don't understand how the second example would let me replace the text with part of the matched text.
Basically, I need to convert $color="red"; to <cfset color="red"> but dynamically, it should work with unknown php variables in the source text.
Seems that matchChunk only lets you know if the match exists (Returns only true/false)
And I don't understand how the second example would let me replace the text with part of the matched text.
Basically, I need to convert $color="red"; to <cfset color="red"> but dynamically, it should work with unknown php variables in the source text.
Seems that matchChunk only lets you know if the match exists (Returns only true/false)
Marcus
Re: Regex help?
Well, there is no parens in the regex?trenatos wrote:Your first example replaced the string with $ding, but you're saying that () won't work.
So, it's me who is confused.
Sorry. As I don't know your skills, it's not easy to give specific answers; it's a wilde area..trenatos wrote: And I don't understand how the second example would let me replace the text with part of the matched text.
matchChunk() or matchText() puts the results pattern in variable(s) after the regex.
The LC coder has to do something with it afterwards.
replaceText() does the replacement automatically in your original text, but you can't use the
capture parens.
I'll come back in a couple of hours with 3-4 lines of code for this..trenatos wrote:Basically, I need to convert $color="red"; to <cfset color="red"> but dynamically, it should work with unknown php variables in the source text.
too busy right now.
Yes, and if it is true, then you work with the variables I spoke above.trenatos wrote:Seems that matchChunk only lets you know if the match exists (Returns only true/false)
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Regex help?
Live and learn, ok so gotIt contains the string match, gotIt1 and gotIt2 are the positions of the first and last characters of the matched string.
convText contains a block of php code.
The above code finds and replaces the $color="red" within a block of text, but it of course fails with subsequent php variables, but it's a start!
convText contains a block of php code.
Code: Select all
get matchChunk( convText, field "regField", gotIt1,gotIt2)
put "\$" & gotIt & ";" into changeMe
put replaceText( convText, changeMe, "<cfset " & gotIt & ">")
Marcus
Re: Regex help?
trenatos wrote:Live and learn,

and here a working solution with some useless extra lines to learn quicker.
well, hope so...
Code: Select all
on mouseUp
local x
put fld 2 into T
-- fld "Regex: (?msi)(\$(\w+=\"\w+\");)
repeat while matchChunk( T, fld "Regex", p1start,p1End,p2Start,p2End)
put "p1start-p1End: " & char p1Start to p1End of T &cr after x
put "p2start-p2End: " & char p2Start to p2End of T &cr after x
get format( "<cfset %s>",char p2Start to p2End of T)
put "new pattern: " & IT &cr after x
put IT into char p1Start to p1End of T
if the controlkey is down then exit repeat
end repeat
put x &cr& T
end mouseUp
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Regex help?
and following my idea from http://forums.runrev.com/viewtopic.php?f=66&t=17412
your solution could have been:
Regards,
Thierry
your solution could have been:
Code: Select all
replaceText( aText, fld "Regex", "<cfset \2>")
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Regex help?
Almost 
Your function actually replaces the variable $color="red"; with this: $<cfset >;
--edit--
waaaait, I forgot to chang the field to the regex in your comment, it totally works now, you have no clue how much that saved my sanity, I can actually continue this project idea now.
I'm curious about your 1-line solution though, have to try that out too

Your function actually replaces the variable $color="red"; with this: $<cfset >;
--edit--
waaaait, I forgot to chang the field to the regex in your comment, it totally works now, you have no clue how much that saved my sanity, I can actually continue this project idea now.
I'm curious about your 1-line solution though, have to try that out too

Last edited by trenatos on Fri Mar 07, 2014 10:07 am, edited 1 time in total.
Marcus
Re: Regex help?
Not here ??trenatos wrote:Almost
Your function actually replaces the variable $color="red"; with this: $<cfset >;
Are you using my latest regex ( put in comments in teh previous script) ?
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Regex help?
Sorry, yes, I edited my last post to reflect that I finally saw your regex in the comment
Marcus