RegEx my LOVE !

Ok, i think i have a Reg-Ex-problem again! xD

I am trying to get a value between two → " searched VALUE here " in a TEXT-STRING → using RegEx.

Normaly this one… —> RegEx —> /“(.*?)”/g
…should work → but doesn’t. Works on an external RegEx-Test-site, but not on LIVE-site.

This one works flawlessly (in Reg-Test-Editor & on my LIVE-site), if i want to search for → [ searched value here ] … ----> RegEx —> /[(.*?)]/g


What am i missing?

No ideas to this issue?
Why the same RegEx is working on other testing-sites, but not on my wix-page? Do i have to add something?

It work well for me.

What? :rofl::sweat_smile: really.
Damn! I will test it again tonight.

Ok, tested it again and again, but still without real success.

This two lines are working well…

.replace(/\[(.*?)]/g, TREFFER1) --> for ---> []

 .replace(/\((.*?)\)/g, TREFFER2) ---> for ---> ( )

But how to generate the same for → " "
and for ----------------------------------------> ’ ’

@russian-dima This is because it’s rich text. Rich text value is an html so you need to use the html that stand for the quotation mark, which is " for double-quote and ' for the single-quote.

@jonatandor35
Damn! But i already tried this → called → ESCAPE and it did not work, for me.
But now doing it a second time → "èt-voilà !!! —> it worked!

BTW: I found once a good site for all the ESCAPES, but lost it again. Do you know a good site, where i can find all the ESCAPES (i call them → ESCAPES :laughing:, because i do not know the right name for it).

Thanks J.D.!!!

@russian-dima Next time you should console.log() the values. Had you done it, you could have found the real characters.
When you say “escapes” do you mean character encoding?

@jonatandor35
I mean some listed “escapes” :sweat_smile: like listed in this example-table, but what i have lost, was a much better table, with all existing → “escapes”

Why, i am calling it → “escapes” :rofl: … because of …(for example)
https://www.freeformatter.com/html-escape.html#ad-output

Perhaps i should read more of this stuff here…

  1. https://learnbyexample.github.io/learn_js_regexp/escaping-metacharacters.html
  2. https://docs.laminas.dev/laminas-escaper/escaping-javascript/
  3. https://javascript.info/regexp-escaping
  4. https://ourcodeworld.com/articles/read/188/encode-and-decode-html-entities-using-pure-javascript

Ok, i think i have to expand my question a little bit.

What i am trying to achieve?

For example i have a text like…

"This is my example text about [JavaScript-programming] . I have to say, that JavaScript is a very interesting [programming-language] and it makes a lot of fun to code with [JavaScript] . I can’t live without JavaScript anymore."

Ok, we have our STRING-TEXT.
Now i want to search for all STRING-TEXT, which is located between the two → [ ]

This part was no problem…

$w.onReady(function () {
 let myString = "This is my example text about [JavaScript-programming]. I have to say, that JavaScript is a very interesting [programming-language] and it makes a lot of fun to code with [JavaScript]. I can't live without JavaScript anymore.";

 let foundStrings = myString.match(/\[(.*?)\]/g);

 for (let i = 0; i < foundStrings.length; i++) {
 const stringElement = foundStrings[i]; console.log(stringElement)
 }
});

All wanted [part-string]s were detected/found and put into an array.
And it would also not be the problem to replace all of the found strings → for example by another single string like → “xxxxxx”, or what ever.

But how i can now replace each individual found STRING with an individual valued STRING. ???

For example if i want to replace → “JavaScript-programming” → to → “Phyton-programming” ?
And if i want to have instead of → “programming-language” → “coding-language” ?
And the third found string should be changed from → “JavaScript” → to → “Ruby” ?

Ok, at least → i was able to solve it! THANKS J.D. + some further researches!

If someone should be interested in such a function, like shown in the next example, just follow this post and all it’s steps…

https://russian-dima.wixsite.com/my-site-1/test

…and perhaps you also will be able to generate such stuff in future.

One more time —> Big thanks goes to J.D. who filled my brain with good ideas again! :laughing:

@russian-dima hi, “escape” is when you need to set a new meaning (functioning) to a certain character,
for example in JS when you wish to represent the ’ character itself and not to use it as string literal, you add a back slash like: "
But here we talked about the html name of specific encoded characters. For that you can see for example these tables (and others):

@jonatandor35 Ok, thanks for clarification J.D. Now all makes sence to me.
Sometimes it’s strage. I do not know about some things, but i already can use them :joy::sweat_smile:

And yes, this is a similar table, which i was talking about. Thanks!

@J.D. Sorry, but still some not understandable issues with RegEx.

let foundStrings = strTEXT . match ( / (&quot(.*?)&quot) / )

Gives back wrong RESULT…


Normaly the RESULT should be → “variable1” and not “;variable1”

Also, if taking a look onto the results, there is something strange…

Instead of one RESULT i get two [0,1]. Why?
That unexpected behaviour destroys my logical way of thinking.
The logical way would be like in this example here, when using →

Clean, logical & understandable result!

Who can shed some light on this behaviour ?

How to modify it to get JUSTvariable1 without quotation-marks and avoiding the first[0] RESULT ?

You forgot the semicolon + you can try something like:

let values = $w("#richTextBox1").value.match(/&quot;((?:\\.|[^&quot;\\])*)&quot;/g).map(e => e.replaceAll("&quot;", ""))

@jonatandor35
Will give you feedback soon. THANKS !:slightly_smiling_face:

@jonatandor35
Ok J.D. , hello again :sweat_smile:

I have done a lot of attemptions to get your suggested CODE working and implementing into my code, but could not get it to work. So i searched for my own way of doing it.

At the end i could solve a lot of issues related to the regEx-syntax (thanks again on this part).
But i switched back to a normal Text-Field instead of using the RTB .

To to disclose the secret, i am working on my own creating of a → CODE- BEAUTIFIER/FORMATTER/ANALYSER/CORRECTOR in one.

But still have some issues, especialy when using rexRex for unescaped characters like → $ or → .

For example if we would have some CODE, which should get formatted …

import wixDatafrom’wix-data’;
var txtSize=“15px”;
const txtMarginLeft0 = “0px”;
const txtMarginLeft1 =‘15px’;
const txtMarginLeft2 = “30px” const txtMarginLeft3 = ‘45px’;
//----------------------------- const txtColor0 = “black”;
const txtColor1 =“blue”;
const txtColor2 =“green”;
const txtColor3= “red”;
const txtColor4 = “violett”;
const txtColor5 = “orange”;
$w.onReady(function(){ var myVariable0=“variable0”;
var myVariable1=‘variable1’;
var myVariable2=‘variable2’;
let myVariable3=10 const myConstant=999;
$w(‘#myButton’).onClick(()=>{ //do something here… });
});

After inserting it into the Text-Box, you normaly get this…


My code-Formatter formats the shown results to…


PROBLEM: How to get → $w.onReady() ← in regEx?

On my understandment —> /$w.onReady()/

  1. / open & close regEx /
  2. escape → $ → ** $
  3. w
  4. escape → . → ** .
  5. STRING —> onReady()

I can get onReady as normal STRING, but not this one → $w.onReady()

EDIT:
This one → /$w.onReady/gmi ← works perfect on every RegEx-Editor, but do not work on my page. :sleepy:

@russian-dima take a look:

https://jonatandor35.wixsite.com/my-site-2

export function richTextBox1_keyPress(event) {
 setTimeout(() => {
 let values = $w("#richTextBox1").value.match(/&quot;((?:\\.|[^&quot;\\])*)&quot;/g) || [];
 $w("#inquot").text = "In Quotations:\n" + values.map(e => e.split("&quot;").join("\n")).join("");
 },30)
}