Jump to content

_StringBetween with rules ?


Go to solution Solved by TheXman,

Recommended Posts

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
Link to comment
Share on other sites

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 !

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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 !

Link to comment
Share on other sites

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? 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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*[^<]*?<)"

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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