Removing part of a text

I have an HTML text in the browser, and I need to delete the whole final part of this text.

For example:

<img src="blob:https://site.com/d38e623a-6a5d-4034-a967-ce0442041760"/>
<br />TITLE<br />
<br />SUBTITLE<br />
<br />TEXT<br />

In this example, I need to delete all after the "img src" closing tag, that is, the entire ending.

Can you help me? :pleading_face:

Hi @Renato_Ribeiro ,
Are you trying to use a snippet to modify the contents of the website?
Or are you using {site: html} and process the HTML?
If you are trying to do the later? What exactly are you trying to use it for so I can assist you better.

Hi @VinodGubbala, I’m trying to modify a content of HTML text, that can be modified directly or by his source code.
There is a logo (with a dinamic link) in the beggining of the text that I want to maintain, and the remaining text I want to delete.

Text Blaze can help you insert text into a field in a website and not modify contents of a website.
Please let me know if I understood you incorrectly, so I can relook at your query.

There is no ways to erase or replace part of a text using Text Blaze?

Another way that I thought, it was using the image insertion of HTML editor. But first, I would need to extract the URL of the “img src” tag, that I mencioned in the example.

If you are trying to insert contents in a field,
you can extract it using {site: html} and then using regex to extract the image url. Which can be used to in the {image} command .
Note: The image extract should always be from the same domain. If this is what you are trying to achieve, I can help you with building this snippet.

Hi @Renato_Ribeiro

Try a snippet like this:

{original_value={site: text; selector=textarea}}{key:ctrl-a; mac=cmd-a}{=replaceregex(original_value, "/>.+", "/>", "s")}

This snippet will:

  1. select all content in the textbox (using the {key} command)
  2. create a new value by clearing all characters after the first closing tag (/>) - using replaceregex() function
  3. insert the new value in place of the selection.

You will need to update the "selector" property in the {site} command to point to the correct textbox - inside which you have the HTML content. Preferably, you should execute this shortcut at the end of the HTML in the text box.

Firstly, thanks guy! I think is what I need.

But, how can I get the correct textbox to insert in the {site} command?

When I use the CSS selector of the "Click element" feature in my textbox, I obtain {click: selector=textarea}. Including, if I use {key: ctrl-a} after that, I can view all the HTML code selected.

But when using the {site} command with selector defined as "textarea" I'm receiving an error of not matching the selector.

This is what I have when I inspect the textbox element:

It looks like your textarea is inside an iframe. Can you change your {site} command to add the "frame=self" property? It would look something like this: {site: text; selector=textarea; frame=self}

I've tried this {site: text; selector=textarea; frame=self} and received the same error:
"Error: No match found for selector: "textarea"."

But the text editor in my page really looks like an iframe, and in the source code I have this:

Are you running your Text Blaze snippet shortcut inside the iframe or outside it?

I start them outside the iframe, but the snippet enter the iframe during its execution.

Try this site command: {site: text; selector=#editor iframe |> textarea}

The {site} commands are calculated first when you run the snippet, before any other action is taken. In your case, you start the snippet outside the iframe, so we need to update the selector to match the textarea starting from outside the iframe.

I still having the message:
"Error: No match found for "#editor iframe |> textarea""

I don't know if it helps, but my front end looks like this:

I see that the text box is inserted into the page after the snippet is inserted. In that case, sadly the {site} command will not work as it is only computed when the snippet is first run.

We hope to support dynamic {site} command but we have no ETA on that yet. See relevant discussion here:

Oh, that's a shame :slightly_frowning_face:
But I think I can achieve my objective by using 'replaceregex' directly in the text editor (out of the HTML editor).
What selector I use to edit the text in this area?

If you're already inside this editor frame, then you can use {site: text; selector=body} to get the text of the editor.

I start the snippet out of the editor frame. Is select the text inside the editor possible? How can I do that?

If you start the snippet outside the editor frame, then the editor must be already present in the HTML of the page when you run the snippet, so that the snippet can read the editor's text.

If it is already present, then you can use the selector I mentioned earlier: {site: text; selector=#editor iframe |> textarea}.
If it is not already present, then the current use case is not possible (pending the feature request I linked above)