Skip to main content
K.Daube
Community Expert
Community Expert
April 13, 2015
Answered

Regex problem

  • April 13, 2015
  • 1 reply
  • 2269 views

Dear friends,

My project again is stuck in a hopefully trivial problem. Until now I searched for items in doulbe brackets, such as [[Dante, #712]]. But this form is somewaht superficial. When using EndNote or Citavi to insert placeholder citations, the form is with braces: {Dante, #712}.

Why does my regex in GetTempCitations find nothing?

I have tested this with RegexBuddy and in my standard program editor (EditPad Pro), where the items are found.

var txt1 = "Hello fans {Dante, #712} and just {some words} and another one {DuçanÌsídõrâ, #312}.";
    GetTempCitations (txt1);

var txt2 =  "introduction to [Content with square brackets] and he rest of something"; 
    otherTest (txt2);

function GetTempCitations (pgfText) {
  var regex = /{([^}]+)}/g;                       // g for global find

  while (result = pgfText.match (regex)) {
    if (result != null) {
      alert (pgfText.match (regex)[1]); 
    }
  }
}

function otherTest (pgfText) {
var regex = /\[([^\]]+)\]/; 
 
  if (pgfText.match (regex) !== null) { 
  alert (pgfText.match (regex)[1]); 
  }   
}

This topic has been closed for replies.
Correct answer JoH

The RegEx should probably be one of these two:

/\{([^\}]+)\}/g

/\{([^}]+)\}/g

Extendscript requires curly brackets to be escaped in order to be taken literally. Inside the character group, the backslash before the closing curly bracket is optional.

(It surprises me a little that the RegEx tester didn't complain.)

var txt1 = "Hello fans {Dante, #712} and just {some words} and another one {DuçanÌsídõrâ, #312}."; 

    GetTempCitations (txt1); 

 

var txt2 =  "introduction to [Content with square brackets] and he rest of something";   

    otherTest (txt2); 

 

function GetTempCitations (pgfText) { 

  var regex = /\{([^\}]+)\}/g;                       // g for global find 

  result = pgfText.match (regex);

  if (result != null) {

    for (var i=0; i < result.length; i++) {

      alert (result);

    }

  } 

 

function otherTest (pgfText) { 

var regex = /\[([^\]]+)\]/;   

   

  if (pgfText.match (regex) !== null) {   

  alert (pgfText.match (regex)[1]);   

  }     

1 reply

JoHCorrect answer
Inspiring
April 13, 2015

The RegEx should probably be one of these two:

/\{([^\}]+)\}/g

/\{([^}]+)\}/g

Extendscript requires curly brackets to be escaped in order to be taken literally. Inside the character group, the backslash before the closing curly bracket is optional.

(It surprises me a little that the RegEx tester didn't complain.)

var txt1 = "Hello fans {Dante, #712} and just {some words} and another one {DuçanÌsídõrâ, #312}."; 

    GetTempCitations (txt1); 

 

var txt2 =  "introduction to [Content with square brackets] and he rest of something";   

    otherTest (txt2); 

 

function GetTempCitations (pgfText) { 

  var regex = /\{([^\}]+)\}/g;                       // g for global find 

  result = pgfText.match (regex);

  if (result != null) {

    for (var i=0; i < result.length; i++) {

      alert (result);

    }

  } 

 

function otherTest (pgfText) { 

var regex = /\[([^\]]+)\]/;   

   

  if (pgfText.match (regex) !== null) {   

  alert (pgfText.match (regex)[1]);   

  }     

gubhare
Participating Frequently
April 30, 2015

Hi JoH,

I am having having similar issues with regex being not working when executed from captivate8. Can you please help finding a resolution.

Following is the link to regex working perfectly in JSfiddle

Edit fiddle - JSFiddle

However the same code is not working when executed from captivate 8. It always says "Driving licence format incorrect"

Any help will be greatly appreciated.

Thanks

gubhare
Participating Frequently
May 4, 2015

Meanwhile I've tried gubhare's script in Captivate 6.0 and found that it does(!) work.

In Captivate 6.0:

Choose File > New Project > Blank Project

On the first slide:

Choose Insert > Standard Objects > Button

Select the button.

In the Actions pane:

Choose On success: Execute JavaScript

Click Script Window

Paste your code into the script window, then close the window.

Press F12 to run the preview in a web browser (on my computer, that's Firefox 37.0.2 + Flash plugin 17.0.0.169).

When I click the button, the browser shows to alerts, first the name, then "Driver licence format correct".


Hi Joh,

Sorry!for delay in reply. I was out all day.

That's really fantastic news. Atleast it works in some version Captivate. I can now inform Adobe that it works in version 6 so it should work in 8 as well.

Thanks once again for your time and effort.

Cheers

Ganesh