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

replace

Guest
Dec 09, 2008 Dec 09, 2008

Copy link to clipboard

Copied

I have string like that "<h2>test page</h2>" in the db.

I would like to remove <h2> and </h2> how can i do that... thanks
either sql server or coldfusion
TOPICS
Advanced techniques

Views

624

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
Participant ,
Dec 09, 2008 Dec 09, 2008

Copy link to clipboard

Copied

the replace function

#Replace("<h2>test page</h2>", "<h2>", "" ,"All")#

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
Dec 09, 2008 Dec 09, 2008

Copy link to clipboard

Copied

see how about </h2>. . dosn't go away

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
Valorous Hero ,
Dec 09, 2008 Dec 09, 2008

Copy link to clipboard

Copied

> I have string like that "<h2>test page</h2>" in the db.

For handling html, regular expressions are usually the best bet. Try one of the functions at cflib.org, such as:
http://www.cflib.org/index.cfm?event=page.udfbyid&udfid=1598

I have not tried that one, but there are several that do a good job with variable white space in tags (< / h2> ) and optional attributes.

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 ,
Dec 09, 2008 Dec 09, 2008

Copy link to clipboard

Copied

Nick201 wrote:
> see how about </h2>. . dosn't go away

You could use a second replace statement for the closing tags.

OR

You could use the rereplace() function with some regular expression
syntax that allows for pattern matching.

#rereplace("<h2>test page</h2>", "<\\*h2>", "" ,"All")#

Untested regex but I think that would be the right one.

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
Participant ,
Dec 09, 2008 Dec 09, 2008

Copy link to clipboard

Copied

well you could run it twice, or use a regular expression to remove them. This will strip all html out of the string.

REReplaceNoCase(<h2>test page</h2>,"<[^>]*>","","ALL");

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
Valorous Hero ,
Dec 09, 2008 Dec 09, 2008

Copy link to clipboard

Copied

Oops. I did not see spill's response before replying ;-)

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
Participant ,
Dec 09, 2008 Dec 09, 2008

Copy link to clipboard

Copied

he he im just too fast for you, but it was worth you posting that function is much more substantial than the standard REReplace as it allows you to specify a specific tag.

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
Valorous Hero ,
Dec 09, 2008 Dec 09, 2008

Copy link to clipboard

Copied

LATEST
Haha. Yes, too slow at the keyboard today 😉

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