• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

PerlRegEx in CF-RegEx

Guest
Oct 28, 2006 Oct 28, 2006

Copy link to clipboard

Copied

Hi,

how can I make this RegEx workin in CF:
$test= join ' ', /(\w*und\w*)/g;

br
Charlie
TOPICS
Getting started

Views

579

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Oct 30, 2006 Oct 30, 2006
> Sorry, I made a mistake with copy&paste. It should be:
> ReReplaceNoCase(variables.myValues, "(\w*und\w*)", "", "All")

I figured as much. So, yeah, that's no cop as you're actively replacing
the bits that you've matched with nothing. You want to replace the bits
you DON'T want with nothing.


> How can I get it work?

<cfset s1 = "and bum candle dumb errand fumble gander humble ireland
jumble">
<cfset s2 = REReplace(s1, "(\w*and\w*)?.*?", "\1,", "ALL")>
<cfset a = listToArray(s2)>
<cfoutput>#...

Votes

Translate

Translate
LEGEND ,
Oct 28, 2006 Oct 28, 2006

Copy link to clipboard

Copied

> Hi,
> how can I make this RegEx workin in CF:
> $test= join ' ', /(\w*und\w*)/g;

A wee bit of RTFM might help:
http://livedocs.macromedia.com/coldfusion/7/htmldocs/00000980.htm

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 29, 2006 Oct 29, 2006

Copy link to clipboard

Copied

Hi Adam,

I know TFM very well and there is no Answer about this, because that doesn't work:
ReReplaceNoCase(variables.myValues, "[^(\w*und\w*)]", "All")

And please don't be as cool as always posting things like: RTFM

br
Charlie

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 29, 2006 Oct 29, 2006

Copy link to clipboard

Copied

> I know TFM very well

Well you *don't*, do you? Or you'd not be asking this question. Because
the link I gave you has all the information you need to sort your issue
out. Did you read it, or did you jump straight to "being indignant"?


>and there is no Answer about this, because that doesn't
> work:
> ReReplaceNoCase(variables.myValues, "[^(\w*und\w*)]", "All")

But that's not the same regex pattern as in your initial question, is it?
In fact that doesn't look valid to me. Serious suggestion: why don't you
work through each construct in that regex above and see if it makes sense
to be doing it. One of the constructs is out of place. I've already given
you a big hint as to what's wrong, in the first sentence of this paragraph.

You've obviously worked out that CF doesn't use "/" delimiters, and "g" for
global: good first steps. But what then made you think you'd have to
adjust the actual pattern? Did you *try* your original pattern to see if
it worked?


> And please don't be as cool as always posting things like: RTFM

Why don't get your head our of your arse? Had I said "RTFM, hahaha" and
that was it, then yours would be a fair comment. However I pointed you to
the relevant section of the docs which I think it was reasonable to assume
you didn't know existed, as you seemed to have a problem with *CF* regexes,
not regexes in general, and I had not taken you to be a *complete*
drop-kick. Not so sure now.

I find the BEST solution to most problems is to be familiar with the
relevant tools, and RTFMing is the best way to get started with that. I
dunno what your approach might be if not that.

So... back to my original suggestion. Go READ the docs, and get familiar
with them.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 29, 2006 Oct 29, 2006

Copy link to clipboard

Copied

Hi,

I'm a CF-Programer since 2000 and I know the documentation.

But you will not find a solution for my problem in the manual!!!
AND you will also not find a solution for that in the book:
Application development (Third edition)

ReReplaceNoCase(variables.myValues, "(\w*und\w*)", "All")

works very well and it delets all the words which have und in it.
But I want the opposite of it, that all strings in variables.myValues will be deleted and not all words with und in it!

I don't believe that you can find the answer for my problem in the manual, or will you?

br
Charlie

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 29, 2006 Oct 29, 2006

Copy link to clipboard

Copied

> I'm a CF-Programer since 2000

Me too!


> and I know the documentation.

Hmmm.


> ReReplaceNoCase(variables.myValues, "(\w*und\w*)", "All")

You have an argument missing from that. Is it your actual code, or just an
example (with a mistake in it)?


> works very well and it delets all the words which have und in it.

So I suspect it's not the actual code you're running, as that example would
replace the first instance of "und" with "All", wouldn't it?


> But I want the opposite of it, that all strings in variables.myValues will be
> deleted and not all words with und in it!

Right. So your regex is matching the correct thing. It's what you're
doing with it that is amiss. Given what you describe of your code (but not
the example you posted, which is different from what you describe), sounds
like you're capturing a match, but replacing it with nowt. That's wrong,
isn't it? What you need to do is capture a match and the "non-matches"
around it, and replace all that with just the match: in effect keeping the
match, but dropping everything else. Think about that for a bit. I think
you're almost there.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 30, 2006 Oct 30, 2006

Copy link to clipboard

Copied

Hello Adam,

>> ReReplaceNoCase(variables.myValues, "(\w*und\w*)", "All")

>>You have an argument missing from that. Is it your actual code, or just an
example (with a mistake in it)?

Sorry, I made a mistake with copy&paste. It should be:
ReReplaceNoCase(variables.myValues, "(\w*und\w*)", "", "All")

And I can't get it work only with ReEx.
With a combination of:
http://www.cflib.org/udf.cfm?id=425
it works very well, but this is not a very fast solution.

How can I get it work?

br
Charlie

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2006 Oct 30, 2006

Copy link to clipboard

Copied

> Sorry, I made a mistake with copy&paste. It should be:
> ReReplaceNoCase(variables.myValues, "(\w*und\w*)", "", "All")

I figured as much. So, yeah, that's no cop as you're actively replacing
the bits that you've matched with nothing. You want to replace the bits
you DON'T want with nothing.


> How can I get it work?

<cfset s1 = "and bum candle dumb errand fumble gander humble ireland
jumble">
<cfset s2 = REReplace(s1, "(\w*and\w*)?.*?", "\1,", "ALL")>
<cfset a = listToArray(s2)>
<cfoutput>#s2#</cfoutput>
<cfdump var="#a#">

NB: busy day @ work today, so only had 5min or so to think about this. It
might not be the best approach. If you look at s2, there's a bunch of
repeated commas in there, which makes me think there'd be a better way to
not step over each intermediary character between matches.

Maybe try some finetuning...

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 30, 2006 Oct 30, 2006

Copy link to clipboard

Copied

Hi Adam,

thank you very much for your great help.

I've never seen such RegEx before.
Now it's at the time that I buy myshelf a good RegEx book!

My task is to extract words from a suchresult, like someone is looking for %and%:

SELECT myField FROM myTable WHERE myField LIKE '%and%'

and then I will get the words in which are the word and is. Now it works, but that's not even the best solution, because myField is a textfield an returns a lot of text.

Now it's on the time that MySQL implements replace with regex functions.

AND now I've found what I was looking:
http://forge.mysql.com/projects/view.php?id=86

But I've to try it first and have to see, if it's much faster, but your help was a great way to learn more about RegEx.

much obliged
Charlie

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2006 Oct 30, 2006

Copy link to clipboard

Copied

LATEST
> thank you very much for your great help.

No probs. Sorry to be so circuitous, but if there's a way for me to "help"
(it's arguable as to how "helpful" my tone can be, sometimes ;-) someone to
work something out for themselves, then I'll take that approach rather than
just giving them the answer.


> http://forge.mysql.com/projects/view.php?id=86

I did not know about that. Excellent. Will come in handy.

Take it easy.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation