Jump to content

Recommended Posts

Posted (edited)
30 minutes ago, mikell said:

May I add, don't double the backslash before Q and E . If you do this, you match the literals "\Q" and "\E"

You aren't using the StringFormat() function to build the string, which is why the double backslashes were used.  As was mentioned and shown earlier, the StringFormat() could have easily been replaced with regular concatenation, in which case, there isn't a need for the double backslash.

Edited by TheXman
Posted

Sorry. I misread your code and didn't pay attention enough to this StringFormat thing
I personally never StringFormat'ed a whole pattern - regex is complicated enough as it is :sweating:

Posted (edited)
20 hours ago, TheXman said:

I made it case-sensitive for a reason.  If it is not case-sensitive, you may change the case of words you did not mean to change.  If it is case-sensitive, then the replacement string can be made to match the case of the search string.

In any case, your modification to make it case-insensitive works for me.

https://regex101.com/r/AJYOL8/1

Unfortunately the regex has a bug 

it is trying to replace "float" which is part of a tag 

https://regex101.com/r/AJYOL8/1

 

image.thumb.png.c516e3ef80756ea9eb469fe612431532.png

 

 

Edited by fraizor

AutoFox, A Modern, Simple, No dependency, Noob friendly yet powerful Firefox UDF !

Posted

It's not a bug. 'float' is not a html-atttribute but part of a html-attribute-value.

The regexp you are using is based on detecting and ignoring html-attributes and uses the trailing '=' to detect and ignore these.

To handle detecting html-attribute-value you will need a different regexp because there is no trailing '='.

Please show some examples of the html code where 'float' must be replaced.

 

Posted
4 minutes ago, OJBakker said:

It's not a bug. 'float' is not a html-atttribute but part of a html-attribute-value.

The regexp you are using is based on detecting and ignoring html-attributes and uses the trailing '=' to detect and ignore these.

To handle detecting html-attribute-value you will need a different regexp because there is no trailing '='.

Please show some examples of the html code where 'float' must be replaced.

 

Thank you for your response 

 

after trying out for 2 hours with regex i came up with this:
https://regex101.com/

 

what do you think ? 

AutoFox, A Modern, Simple, No dependency, Noob friendly yet powerful Firefox UDF !

Posted
3 minutes ago, fraizor said:

after trying out for 2 hours with regex i came up with this:
https://regex101.com/

Are you trying to say that you came up with nothing or did you paste the wrong link? 

Posted (edited)

Solely based on the HTML samples that you have supplied, the search text is always immediately preceded by a ">".  If that will always be the case, then the following regular expression might work for you.  If it can have zero or more spaces after the ">" but before the search text, then you can easily make that modification to the pattern.

Func _HTML_ReplaceAllText($sSource, $sSearchText, $sReplaceText)
    Return StringRegExpReplace( _
                               $sSource, _
                               "(?i)(>)\Q" & $sSearchText & "\E", _
                               "$1" & $sReplaceText _
                               )
EndFunc

https://regex101.com/r/fIGif2/1

 

Edited by TheXman
Posted

The following seems to work for 'Style' and 'float'.

In words: search text after a tag and before the next tag, with optional spacing before/after the search text.

"(?i)(<[^>]*?[^>]*?>\s*)\Q" & $sSearchText & "\E(\s*[^<]*?<)"

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...