How to remove html tags without /n in ruby's regular expression

Asked 2 years ago, Updated 2 years ago, 30 views

Error Occurring

railsc cannot use helpers.strip_tags when playing scripts.
If you try to remove the html tag with gsub and regular expression, a new line code of "/n" will also be included

Expected behavior

I want to erase the html tag without /n in the middle below

<p>Yamada/n Taro</p>

Error Contents

By describing this regular expression, html tags (p tags) can be removed, but "/n" can also be removed altogether.

User.first.User_name.gsub(/<("[^"]*"|'[^']*'|[^'">])*>/, "")

Tried

Tried the description except "/n" before specifying the html tag.
I can't remove it well.

User.first.User_name.gsub(^(?!.*/n).$/<("[^"]*"|'[^']*'|'[^']*'|[^'">])*>/, "")

The condition is

  • Remove tags

  • Except line feed codes

remove a tag

I'm in trouble because I can't use regular expressions well.
If you have any knowledge, I would appreciate it if you could let me know.

ruby-on-rails ruby html

2022-09-29 21:21

1 Answers

Actually,

If you play scripts in railsc, helpers.trip_tags are not available.

It doesn't mean that inside the console,

include ActionView::Helpers::SanitizeHelper

Then the trip_tags method can be called.


2022-09-29 21:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.