Regular Expression

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
slashmaster
Posts: 29
Joined: Fri May 25, 2018

27 Jul 2018

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 2064 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

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

27 Jul 2018

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.
Cheers

slashmaster
Posts: 29
Joined: Fri May 25, 2018

06 Aug 2018

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
Last edited by slashmaster on 07 Aug 2018, edited 1 time in total.

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

06 Aug 2018

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.
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 24 guests