3 oddities

Users and developers helping users with generic and technical Pale Moon issues on all operating systems.

Moderator: trava90

Forum rules
This board is for technical/general usage questions and troubleshooting for the Pale Moon browser only.
Technical issues and questions not related to the Pale Moon browser should be posted in other boards!
Please keep off-topic and general discussion out of this board, thank you!
markfilipak

3 oddities

Unread post by markfilipak » 2019-05-17, 19:27

HTML.
In an HTML file containing this text: "|<", Pale Moon (and Windows Edge, too) hides it and the rest of the line (up to, but not including "\n"). But if the HTML is a web page from the net, they don't do any hiding.

Javascript.
The '.replace' method can utilize regular expressions (<sourcetext>.replace(/<rebody>/g,function(){}), and those regular expressions utilize the '.lastIndex' property, and '.lastIndex' is supposed to be writable, but (unlike other regular expression methods) writing it does not work (does not move the source index). There are a couple of workarounds.

Javascript.
Regular expression terms are supposed to be greedy by default, however, /\.+/ is non-greedy by default. Workaround: /(\.+)([^\.])/ and do this: '<re>.lastIndex--', in the function -- that's supposing that '.lastIndex' works (see previous paragraph).
Last edited by markfilipak on 2019-05-17, 21:34, edited 1 time in total.

User avatar
therube
Board Warrior
Board Warrior
Posts: 1651
Joined: 2018-06-08, 17:02

Re: 3 oddities

Unread post by therube » 2019-05-17, 20:32

Oh, I know about zero JavaScript & about one in Regex...

Seems * & + should be greedy, PCRE Regex Cheatsheet.

But BRU & Everything look to indicate that they're searching non-greedy?
(Unless my (.*) is throwing things off. And given that regex differs depending on implementation...)
.
RegEx dot plus.png

markfilipak

Re: 3 oddities

Unread post by markfilipak » 2019-05-17, 21:32

Howdy,

/\./+/ is not /.+/ (and /\.*/ is not /.*/).

In each case, the 1st matches '.', the 2nd matches any character (and end-of-line, whether 1 char or 2 chars). The 2nd may -- probably does -- work properly.

A greedy term can be made non-greedy by adding '?', but a non-greedy term that is supposed to be greedy cannot be made greedy except by the technique I presented.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35602
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: 3 oddities

Unread post by Moonchild » 2019-05-18, 11:41

Just a note: Please don't expect browser regex to be 100% PCRE compliant -- it isn't and won't be.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

markfilipak

Re: 3 oddities

Unread post by markfilipak » 2019-05-18, 23:59

Hi MC!
Moonchild wrote:
2019-05-18, 11:41
Just a note: Please don't expect browser regex to be 100% PCRE compliant -- it isn't and won't be.
I'm not writing production code. I'm writing a format translator: from tokenized-text to HTML, for my own use, as a bulk utility. All that I require is that regex be consistent and predictable. I just thought I would share what I've found that seems inconsistent, for your (and others') benefit.

My latest discovery is that regex seems to think that /\n/ doesn't match /[^\|]/. I'm working on a workaround.

User avatar
adesh
Board Warrior
Board Warrior
Posts: 1277
Joined: 2017-06-06, 07:38

Re: 3 oddities

Unread post by adesh » 2019-05-19, 06:31

About consistency:
In practive I've found that Regex is almost never consistent. There are different flavours that different languages and platforms support, be it Java, Bash, Vim, JavaScript etc. For this reason I always thoroughly test regex related functionality instead of relying on consistency.

markfilipak

Re: 3 oddities

Unread post by markfilipak » 2019-05-19, 08:38

Thanks for your reply. By "consistent" I meant consistent solely within PM, not consistent across differing implementations of regex.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35602
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: 3 oddities

Unread post by Moonchild » 2019-05-19, 23:22

I strongly recommend you have a look at regexbuddy. It's a great tool that supports tons of regex dialects, offers immediate regex analysis and testing of the resulting rules.
http://www.regexbuddy.com/
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

markfilipak

Re: 3 oddities

Unread post by markfilipak » 2019-05-19, 23:32

Thanks, MC. I'll look it over.

New Tobin Paradigm

Re: 3 oddities

Unread post by New Tobin Paradigm » 2019-05-20, 01:44

I personally favor https://regex101.com/ my self because I simply need something quick when I have no choice but to use a regex. But Moonchild's option would be superior.

Locked