Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to test for repeatedly occuring strings

1 view
Skip to first unread message

Heinz Kesting

unread,
Jun 25, 2017, 12:46:35 PM6/25/17
to
Bon jour,

Après j'ai appris récemment ici le soutien magnifique, je dois encore
demander l'aide.
Cette fois, il s'agit de l'éloignement aux hyperliens existants. Puisque
l'usager (non projeté ?) le texte peut marquer qui contient plusieurs
hyperliens, plusieurs links seraient enlevés alors aussi involontaire -
cela devait être évité naturellement.
Le passage suivant est un texte d'exemple de quoi un link ernfernt doit
devenir:

.... If you use the <a href="ID_15">Microsoft</a> Windows Scripts
installation package, the <a href="ID_15">DLL</a> will be registered for
you. You should also note that many versions of Microsoft Windows and <a
href="ID_66">Internet Explorer</a> include these scripting engines, so
it is very <a href="ID_19">likely</a> that you will not need to install
them .....

De manière acceptée, l'usager voulait enlever le link du mot "likely", a
marqué cependant (par erreur) la phrase totale
... You should also note that many versions of Microsoft Windows and <a
href="ID_66">Internet Explorer</a> include these scripting engines, so
it is very <a href="ID_19">likely</a> that ...

Maintenant, la fonction enlèverait les deux links, d' "Internet
Explorer" et AUSSI de "likely" - ce qui ne serait pas naturellement richt.
Je cherche RegExp qui trouve SEULEMENT de la chaîne dans laquelle les
mots partiels <a href=" et </a> arrivent exactement une FOIS.

Le modèle suivant trouve un hyperlien correct:
[<a href=".+?">.+?</a>]
Donc je l'ai tenté avec la modification suivante
[<a href="{1,1}.+?">{1,1}.+?</a>{1,1}]
pour exprimer que les mots suivants peuvent arriver seulement exactement
une fois: <a href=", "> and </a>
... naturellement sans succès!

J'espère, cela peut m'aider ici quelqu'un!
La traduction on-line est espérons que compréhensible.
Plusieurs remercie et beaucoup de saluts, Heinz


**** English original text ****
after having received great help here recently, I need to ask for
assistance once again.
This time it's about removing an existing hyperlink from a text. Since
it could be possible that the user (perhaps by mistake) would select a
text passage that contains more than one hyperlink, he could thus remove
the other selected hyperlink(s) as well - which should be prevented, of
course.

The following paragraph serves as an sample text from which the link
should be removed:

.... If you use the <a href="ID_15">Microsoft</a> Windows Scripts
installation package, the <a href="ID_15">DLL</a> will be registered for
you. You should also note that many versions of Microsoft Windows and <a
href="ID_66">Internet Explorer</a> include these scripting engines, so
it is very <a href="ID_19">likely</a> that you will not need to install
them .....

Say, the user wanted to remove the hyperlink from the string "likely",
but he selected (by mistake) the whole sentence from:

... You should also note that many versions of Microsoft Windows and <a
href="ID_66">Internet Explorer</a> include these scripting engines, so
it is very <a href="ID_19">likely</a> that ...

Now the function would remove both links, the one for the string
"Internet Explorer" AND "likely", as well.
So I need a RegExp that matches only strings where the key substrings
<a href=" and </a>
appear ONLY once.

The following pattern finds a correct hyperlink:
[<a href=".+?">.+?</a>]
So I tried my best idea with something like
[<a href="{1,1}.+?">{1,1}.+?</a>{1,1}]
to express that the substrings <a href=", "> and </a> have to be present
exactly ONE TIME - but without success.

Can somebody here help?

Thanks for taking trouble to look into this ...

Kind regards, Heinz

Olivier Miakinen

unread,
Jun 25, 2017, 2:30:50 PM6/25/17
to
Le 25/06/2017 18:46, Heinz Kesting a écrit :
> Bon jour,

Bonjour,

> [...]
> J'espère, cela peut m'aider ici quelqu'un!
> La traduction on-line est espérons que compréhensible.

En fait non. La traduction automatique est très drôle, mais pas
du tout compréhensible. Alors je vais répondre au texte en anglais,
tout en écrivant moi-même en français. Par respect pour les lecteurs
francophones, je vais même traduire d'abord les questions avant d'y
répondre.

> This time it's about removing an existing hyperlink from a text. Since
> it could be possible that the user (perhaps by mistake) would select a
> text passage that contains more than one hyperlink, he could thus remove
> the other selected hyperlink(s) as well - which should be prevented, of
> course.

| Cette fois il s'agit de supprimer un hyperlien existant d'un texte.
| Il est possible que l'utilisateur (peut-être par erreur) sélectionne
| un passage du texte contenant plus d'un hyperlien, et supprime les
| autres hyperliens sélectionnés -- ce qui doit bien sûr être évité.

> The following paragraph serves as an sample text from which the link
> should be removed:

| Le paragraphe suivant servira d'exemple de texte dont un lien doit
| être supprimé :

> .... If you use the <a href="ID_15">Microsoft</a> Windows Scripts
> installation package, the <a href="ID_15">DLL</a> will be registered for
> you. You should also note that many versions of Microsoft Windows and <a
> href="ID_66">Internet Explorer</a> include these scripting engines, so
> it is very <a href="ID_19">likely</a> that you will not need to install
> them .....
>
> Say, the user wanted to remove the hyperlink from the string "likely",
> but he selected (by mistake) the whole sentence from:

| Mettons que l'utilisateur voulait supprimer l'hyperlien de la chaîne
| « likely » mais qu'il a sélectionné (par erreur) la phrase complète :

> ... You should also note that many versions of Microsoft Windows and <a
> href="ID_66">Internet Explorer</a> include these scripting engines, so
> it is very <a href="ID_19">likely</a> that ...
>
> Now the function would remove both links, the one for the string
> "Internet Explorer" AND "likely", as well.
> So I need a RegExp that matches only strings where the key substrings
> <a href=" and </a>
> appear ONLY once.

| La fonction supprimerait les deux liens, celui pour la chaîne
| « Internet explorer » et celui pour « likely ». Donc j'ai besoin d'un
| RegExp qui ne réussisse que si les sous-chaînes clés n'apparaissent
| qu'UNE fois.

Tout d'abord, je ne comprends pas ton besoin. Si un utilisateur veut
supprimer plusieurs liens d'affilée, pourquoi lui interdire de le
faire ?

Par exemple en PHP :

preg_replace('/<a href=".+?">(.+?)<\/a>/', '$1', '.... You should also
note that many versions of Microsoft Windows and <a
href="ID_66">Internet Explorer</a> include these scripting engines, so
it is very <a href="ID_19">likely</a> that ..... ');

Ceci donnera :
.... You should also note that many versions of Microsoft Windows and
Internet Explorer include these scripting engines, so it is very likely
that .....

Bien sûr, il suffit de laisser la possibilité de défaire ce qu'il vient
de faire (« undo ») si jamais il s'était trompé. Mais si ce n'était pas
une erreur, pourquoi l'interdire ?

> The following pattern finds a correct hyperlink:

| L'expression suivante trouve un hyperlien correct :

> [<a href=".+?">.+?</a>]

Note 1, pour les reluqueurs (en: lurkers) : avec les PCRE, du moins en
PHP, les délimiteurs [ et ] en début et fin sont possibles, et ne pas
utiliser // comme délimiteurs permet de ne pas avoir à échapper les /
dans la RegExp.

Note 2 : j'y ajouterais bien des parenthèses de capture, comme dans mon
exemple ci-dessus.

> So I tried my best idea with something like

| Alors j'ai essayé ma meilleur idée avec quelque chose comme...

> [<a href="{1,1}.+?">{1,1}.+?</a>{1,1}]

Ahem. Cette expression est *strictement* identique à la précédente. La
seule différence, c'est que tu as remplacé « " » (je veux un « " »)
par « "{1,1} » (je veux un « " » une fois et une seule), puis pareil
avec chacun des deux « > ».

> to express that the substrings <a href=", "> and </a> have to be present
> exactly ONE TIME - but without success.

| pour exprimer que les sous-chaînes <a href=", "> et </a> doivent être
| présentes exactement UNE FOIS -- mais sans succès.

Comme je l'ai dit ci-dessus, chacun de tes {1,1} s'applique à un seul
caractère. En outre, ils expriment juste localement « j'en veux un à
cet endroit », et n'ont aucune incidence sur l'évaluation globale de
la RegExp.

Par exemple, supposons que tu veuilles repérer des séquences d'une
ou plusieurs fois Abc dans la chaîne HelloAbcAbcAbcHello, la RegExp
/(Abc)+/ va bien trouver les trois : AbcAbcAbc. Supposons maintenant
que tu remplaces ta RegExp par : /(Ab{1,1}c)+/. Même si tu as précisé
que tu ne voulais qu'un seul b, cette RegExp donnera aussi comme
résultat AbcAbcAbc, car chacun des trois b est bien tout seul là où
il est détecté dans la RegExp.



Maintenant deux choses.

La première, et j'aurais peut-être dû en parler dès ton premier message
ici, c'est que pour manipuler du HTML les RegExps ne sont pas forcément
la meilleure solution. Voir <http://simplehtmldom.sourceforge.net/> par
exemple.

La seconde, c'est que si vraiment tu veux limiter le nombre de
remplacements, avec preg_replace(¹) il suffit de rajouter un paramètre
« limit » à 1, seulement ça ne gardera que le premier et pas le dernier
contrairement à ton exemple.

(¹) Ça, c'est si tu programmes en PHP. Je crois que tu n'as jamais dit
quel langage tu utilises. Mais il y a sûrement l'équivalent dans les
autres langages.

--
Olivier Miakinen

Heinz Kesting

unread,
Jun 26, 2017, 5:26:32 PM6/26/17
to
Hallo Olivier,
>> [...]
>> J'espère, cela peut m'aider ici quelqu'un!
>> La traduction on-line est espérons que compréhensible.

I'll stick to English, since the online translation has been worse than
I had expected.

The most important thing first - driven by your reply I did some more
studying, and fortunately I found a solution pretty soon.
It's the so-called MATCHES COLLECTION. With this technique I can easily
determine how many times a certain match is contained in the search
string, and that's what I need for my current issue.

form.oRegExp.pattern = [<a href="]
aMatch = form.oRegExp.execute(form.entryfield2.value)
? "aMatch.count = " + aMatch.count

The last line of the above code example prints the string "aMatch.count
= " to the screen (for testing), followed by the actual number of
matches found in the search string. If there is exacty ONE match, I can
be sure that the user hasn't selected more than one hyperlink and I can
let him preceed deleting the link.

You asked for the programming language I am working with. No, it's not
PHP nor HTML, I am using dBase (www.dbase.com), which is actually a
database software with an implemented object orientated programming
language.
At the moment I am working on a kind of private Rock/Pop lexicon, based
on a relational database system. Here I display the biographies of the
bands and musicians in a web browser object, where the user can click on
linked words or word groups to jump to the corresponding data, just like
you do on a web page.
The biograhy itself is stored as plain text in a database field, where
an admin is inserting or deleting the links.
With the RegExp functions I asked for support here, I am trying to make
the process of editing the links less error-prone.

Using RegExp formulas make it so much easier to program such searches,
with native functions the programme code would be much more complicated,
and certain things are impossible without extern functionality like
RegExp or other API functions ....

Thanks once more for your help!

Kind regards, Heinz
0 new messages