Home Forum
2024-12-30
Benvenuto, Ospite
Nome Utente Password: Ricordami

Negative Lookahead Assertions
(1 Online) (1) Ospite
  • Pagina:
  • 1

ARGOMENTO: Negative Lookahead Assertions

Negative Lookahead Assertions 13 Anni fa #2860

  • cmb
  • Offline
  • Fresh Boarder
  • Messaggi: 13
Are negative lookahead regular expression assertions supported by ReDJ?

For example, I have a From URL of:
^/section_alias/(?!category_alias/)

That should match a URL that begins with /section_alias/ and is not followed by category_alias/.

An example: www.example.com/section_alias/article_title.html

I would like to capture all instances of URLs with the missing element and insert it. The To URL is:
{scheme}://{siteurl}/section_alias/category_alias/{pathltrim /section_alias/}{queryfull}

The generated URL should be:
www.example.com/section_alias/category_alias/article_title.html
but it is not working.

ReDJ 1.5.6, Joomla 1.5.25
L'Argomento è stato bloccato.

Re: Negative Lookahead Assertions 13 Anni fa #2861

  • admin
  • Offline
  • Administrator
  • Messaggi: 1603
Hi,
you need a "From URL" rule that matches only the needed URLs. The regexp supported in the From URL is the same of MySQL:

dev.mysql.com/doc/refman/5.0/en/regexp.html

Maybe you can find a way to do this:

Posted by Kasey Speakman on November 10 2010 7:53pm

It's quite unfortunate that their REGEX interpreter doesn't support logical NOT expressions. Ordinarily I would write something like this to match all numbers except 11:

(?!^11$)^\d+$

But with their implementation, I have to make a "do not match" field as well as a "match" field to make sure my conditions are met. :/
Posted by Andrey Klyuchnikov on March 1 2011 11:52am

re: Kasey Speakman

^([0-9]|[02-9][02-9]|[0-9][02-9]|[02-9][0-9]|[0-9]{3,})$

L'Argomento è stato bloccato.

Re: Negative Lookahead Assertions 13 Anni fa #2864

  • cmb
  • Offline
  • Fresh Boarder
  • Messaggi: 13
From the dev.mysql.com/doc/refman/5.0/en/regexp.html page:
[^a-dX] Matches any character that is not either a, b, c, d or X

I want to detect that category_alias/ is missing and then insert it. To take the minimal case, let's just look for the missing c in category_alias/ like this in the From URL:
^/section_alias/[^c]

The To URL remains:
{scheme}://{siteurl}/section_alias/category_alias/{pathltrim /section_alias/}{queryfull}

The From URL string works outside ReDJ in a regular expression tester as expected. But using my previous example, www.example.com/section_alias/article_title.html, is not recognized inside ReDJ. The rule is never triggered.

Can you see where my mistake is?
L'Argomento è stato bloccato.

Re: Negative Lookahead Assertions 13 Anni fa #2868

  • admin
  • Offline
  • Administrator
  • Messaggi: 1603
Can you send me a dump of ReDJ table? I would like to import rule exactly in my test env. If you prefer, send me a mail at info(at)sistemistica.it.

Cheers,
Luigi
L'Argomento è stato bloccato.

Re: Negative Lookahead Assertions 13 Anni fa #2877

  • cmb
  • Offline
  • Fresh Boarder
  • Messaggi: 13
Okay, the ReDJ table dump has been emailed.
L'Argomento è stato bloccato.

Re: Negative Lookahead Assertions 13 Anni fa #2884

  • admin
  • Offline
  • Administrator
  • Messaggi: 1603
I send you an email.
L'Argomento è stato bloccato.

Re: Negative Lookahead Assertions 13 Anni fa #2888

  • cmb
  • Offline
  • Fresh Boarder
  • Messaggi: 13
I look forward to receiving it.
L'Argomento è stato bloccato.

Re: Negative Lookahead Assertions 13 Anni fa #2890

  • admin
  • Offline
  • Administrator
  • Messaggi: 1603
Hi,
maybe you didn't receive my last mail. This is my question.

The rule that didn't work is:

(1253, '^/car-rentals/[^r]', '{scheme}://{siteurl}/car-rentals/rental-car-tips-and-advice/{pathltrim /car-rentals/}{queryfull}', 301, 0, 0, '2011-12-08 15:01:24', 1, 1, 0, '0000-00-00 00:00:00')

The initial caret means "start with", but you want to apply this rule to:

localhost/gemut/car-rentals/3772-times-gets-it-wrong-on-renting-a-car-in-europe.html

That start with /gemut. For these case and to simplify rule portability, I've added a plugin advanced option that allows you to specify the base path (i.e. /gemut in your case).

Have you already done this?

Please advise,
Luigi
L'Argomento è stato bloccato.
Ringraziano per il messaggio: cmb

Re: Negative Lookahead Assertions 13 Anni fa #2895

  • cmb
  • Offline
  • Fresh Boarder
  • Messaggi: 13
admin ha scritto:
For these case and to simplify rule portability, I've added a plugin advanced option that allows you to specify the base path...
Have you already done this?

Eureka! I had not done that. I have three copies of the Website in question and decided to use the one within the XAMPP installation on my own computer for testing. That is the only one that requires the non-blank Base Path. (Administrator > Extensions > Plugin Manager > System - ReDJ > Advanced > Advanced Parameters > Base Path)

Note that in the To URL field, the pathltrim must also contain the base path addition. From the example in my original posting to this thread, the To URL now becomes:
{scheme}://{siteurl}/section_alias/category_alias/{pathltrim /<subdirectory_name>/section_alias/}{queryfull}
where needed. In my case, <subdirectory_name> will be gemut.

After I got that redirect rule working on my local installation, I installed and tested it on the online test site and the online public site. All those work correctly.

Also I installed and verified the rule that covers more letters in the test. From the original example, one such From URL will be:
^/section_alias/[^c][^a][^t][^e][^g][^o][^r][^y]
If the word category does not follow the section alias, the rule is triggered.
Ultima modifica: 13 Anni fa Da cmb.
L'Argomento è stato bloccato.

Re: Negative Lookahead Assertions 13 Anni fa #2896

  • admin
  • Offline
  • Administrator
  • Messaggi: 1603
First thanks for your detailed description.

From these I've noticed that macro "pathltrim" can be improved adding an option to "ignore" base path. This increase rules portability.

Really thanks for this.

Luigi
L'Argomento è stato bloccato.
  • Pagina:
  • 1
Moderatori: admin
Tempo generazione pagina: 0.49 secondi
Cerca con Google
News
Chi è online
 159 visitatori online
Sponsor

slotmachineaamsonline.com è una guida alle migliori slot machine online legali in Italia. Sul sito trovi un elenco sempre aggiornato dei casino online con Slot machine e bonus slot, le ultime novità dal mondo delle slot online e le migliori strategie per vincere. Inoltre, è disponibile una sezione dedicata alle slot machine da BAR che finalmente sono disponibili nella versione online.