Page 1 of 1

Regular Expression

Posted: 27 Jul 2018
by slashmaster
Hello,

i try to use a simple regular Expression, to get some Text into an Array.
I have a Text-Field with the following Content:

Code: Select all

<a href="" target="_self">Text123</a> some other text <a href="" target="_self">Textyxz</a> and some text i dont want <a href =""> dont want to </a> 
And a the following Regular Expression:
/(target="_self">).*?(<\/a>)/g

I tested it on https://www.regexpal.com/ (see Picture). The Regular Expression works well.
regex.JPG
regex.JPG (36.96 KiB) Viewed 2067 times
This code i use in Forms-Designer:

Code: Select all

vartext = $(".csshtmldummy").text();
var patt = new RegExp("(target=\"_self\">).*?(<\/a>)", "g");
var match = patt.exec(vartext);
alert(match.length);
The Result:
match.length == 3 (wrong)
match[0] == target="_self">Text123</a> (correct)
match[1] == target="_self"> (wrong)
match[2] == </a> (wrong)

where am I going wrong??? :roll:

Best regards

Re: Regular Expression

Posted: 27 Jul 2018
by Nikita Kurguzov
Dear slashmaster,
From all of our tests - everything works correctly, it all works. Please, test it from the browser's console as well, it should give you more insight into the errors. Perhaps, the value retrieved from a text field is different, one thing I can think of. If not - send us screenshots with errors.

Re: Regular Expression

Posted: 06 Aug 2018
by slashmaster
Hi,

i got no Errors... anyway, i solved this Problem with another code:

Code: Select all

vartext = $(".csshtmldummy").text();
var patt = /(target="_self").*?(<\/a>)/g;
var myArray = vartext.match(patt); 
console.log(myArray);
thank u

Re: Regular Expression

Posted: 06 Aug 2018
by Nikita Kurguzov
Great to hear that! Sorry we couldn't help further, still not sure what could've caused it, but we're glad that the solution you found works! Let us know if you need anything - we'll do our best to help.