3 oddities

Users and developers helping users with technical Pale Moon issues (Windows and other non-Linux O.S.). Please direct questions about the Linux version to the appropriate Linux board.

Moderators: trava90, satrow

Forum rules
This board is for technical/usage questions and troubleshooting for the Pale Moon browser only. The main focus here is on Pale Moon on Windows. Please direct your questions for Linux, Android and Mac to the dedicated boards.
Technical issues and questions not related to the Pale Moon browser should be posted in "technical chat"
Please keep off-topic and general discussion out of this board, thank you!
User avatar
markfilipak
Fanatic
Fanatic
Posts: 213
Joined: 2015-02-26, 22:23
Location: Mansfield, Ohio, U.S.A.

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: 1006
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

User avatar
markfilipak
Fanatic
Fanatic
Posts: 213
Joined: 2015-02-26, 22:23
Location: Mansfield, Ohio, U.S.A.

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: 23975
Joined: 2011-08-28, 17:27
Location: 58°2'16"N 14°58'31"E
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.
City of Heroes public server: https://www.moonshard.org/ -- Vote for it on cohservers.com

"If you want to build a better world for yourself, you have to be willing to build one for everybody." -- Coyote Osborne
Image

User avatar
markfilipak
Fanatic
Fanatic
Posts: 213
Joined: 2015-02-26, 22:23
Location: Mansfield, Ohio, U.S.A.

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
Astronaut
Astronaut
Posts: 671
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.

User avatar
markfilipak
Fanatic
Fanatic
Posts: 213
Joined: 2015-02-26, 22:23
Location: Mansfield, Ohio, U.S.A.

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: 23975
Joined: 2011-08-28, 17:27
Location: 58°2'16"N 14°58'31"E
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/
City of Heroes public server: https://www.moonshard.org/ -- Vote for it on cohservers.com

"If you want to build a better world for yourself, you have to be willing to build one for everybody." -- Coyote Osborne
Image

User avatar
markfilipak
Fanatic
Fanatic
Posts: 213
Joined: 2015-02-26, 22:23
Location: Mansfield, Ohio, U.S.A.

Re: 3 oddities

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

Thanks, MC. I'll look it over.

User avatar
New Tobin Paradigm
Off-Topic Sheriff
Off-Topic Sheriff
Posts: 5613
Joined: 2012-10-09, 19:37
Location: Sector 001

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.
Image
- So then, "mono" means one, and "rail" means rail! -
And that concludes our intensive three-week course.
http://binaryoutcast.com/ | http://thereisonlyxul.org/

Post Reply