• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Regex problem

Community Expert ,
Apr 13, 2015 Apr 13, 2015

Copy link to clipboard

Copied

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]); 
  }   
}

TOPICS
Scripting

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Apr 13, 2015 Apr 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 brac

...

Votes

Translate

Translate
Explorer ,
Apr 13, 2015 Apr 13, 2015

Copy link to clipboard

Copied

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]);   

  }     

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 13, 2015 Apr 13, 2015

Copy link to clipboard

Copied

Thank You Joh,

However, the probelm is: wich RegEx flavour is active in Escript?

I have tested against PowerGrep, Gnu ERE, JavaScript (MSIE Standard), Perl 5.20:

In Perl the braces enclose a match counter, e.g. {n} Match exactly n times. But there are exceptions to this: If a curly bracket occurs in any other context and does not form part of a backslashed sequence like \x{...} , it is treated as a regular character. In particular, the lower quantifier bound is not optional, and a typo in a quantifier silently causes it to be treated as the literal characters.

RegexBuddy allows to test in about 40 different flavours of RegEx syntax. So I assumed to be on the safe side...

Where are the details of RegEx syntax for ExtendScript (and the flavours used in FrameMaker which use the Boost library) documented?

For FM I found this: http://www.boost.org/doc/libs/1_34_0/libs/regex/doc/syntax_perl.html

But for ExtendScript ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 13, 2015 Apr 13, 2015

Copy link to clipboard

Copied

Hi Klaus, ExtendScript is just using the standard JavaScript regular expressions syntax. It has no relation to the Regular Expressions libraries built into FrameMaker 12. -Rick

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 13, 2015 Apr 13, 2015

Copy link to clipboard

Copied

I can't tell exactly what Regex flavour ExtendScript is using.

When you look at the following examples, you'll notice a difference between Extendscript and Javascript as used in web browsers:

1. Save the following code as an HTML file and open it in a browser. Both Regex patterns are evaluated as "true".

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8"/>

<script type="text/javascript">

function re_test() {

  var txt = "this is {my} text";

  var pattern = /{[^}]+}/;

  containsText = pattern.test(txt);

  alert(containsText);

 

  var pattern2 = /\{[^}]+\}/;

  containsText = pattern2.test(txt);

  alert(containsText); 

 

}

</script>

</head>

<body onload="re_test();">

</body>

</html>

2. Run the following code in Extendscript. The first Regex pattern is evaluated as "false", the second as "true".

re_test();

function re_test() {

  var txt = "this is {my} text";

  var pattern = /{[^}]+}/;

  containsText = pattern.test(txt);

  alert(containsText);

 

  var pattern2 = /\{[^}]+\}/;

  containsText = pattern2.test(txt);

  alert(containsText); 

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 13, 2015 Apr 13, 2015

Copy link to clipboard

Copied

To be honest with you, I am a little surprised at this. Because curly braces are a special regex character, I would think that you would always have to escape them. I wouldn't expect the first one to be true in the browser. Maybe the browser engine is smart enough to know that there is no other regex token before the curly braces, so it interprets it as a literal character. I think you are always safest when you escape characters like this.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 30, 2015 Apr 30, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 30, 2015 Apr 30, 2015

Copy link to clipboard

Copied

Sorry to disappoint you, but this is far beyond my knowledge in Captivate. Maybe you can try a simpler expression. I've seen other software where RegEx elements like positive lookahead (?=...) were not supported. This is only a guess, not sure if this applies to Captivate.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 30, 2015 Apr 30, 2015

Copy link to clipboard

Copied

Hi Joh,

Thanks for your quick reply and appreciate your help.

Maybe some Captivate Guru will help me out.

Have a great day.

Regards

Ganesh

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 30, 2015 Apr 30, 2015

Copy link to clipboard

Copied

What does the code in Captivate look like? Post it here and I will try to troubleshoot it. -Rick

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 30, 2015 Apr 30, 2015

Copy link to clipboard

Copied

Hi Frameexpert,

Thanks for your reply.

Its the same piece of code I used in JSFiddle where it works perfectly.  I used the same code in Captivate as well by executing javascript but does not work through captivate. Here's the code

var re = /^(?=.{16}$)[A-Za-z]{1,5}9{0,4}[0-9](?:[05][1-9]|[16][0-2])(?:[0][1-9]|[12][0-9]|3[01])[0-9](?:99|[A-Za-z][A-Za-z9])(?![IOQYZioqyz01_])\w[A-Za-z]{2}/;

var str = "SMITH707173SK9GP";

var m;

alert(str);

if ((m = re.exec(str)) !== null) {

    if (m.index === re.lastIndex) {

        re.lastIndex++;

    }

    alert("Driver licence format correct");

}

else

{

    alert("Invalid driver licence format. Please check your driving licence and enter the correct format.");

}

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 30, 2015 Apr 30, 2015

Copy link to clipboard

Copied

In the ExtendScript Toolkit it says "Driver license format correct", which I assume is correct. What are the rules that the driver license has to follow? Can you spell them out in plain English? Also, assuming that your example string is correct, can you provide an example that would be incorrect? Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 30, 2015 Apr 30, 2015

Copy link to clipboard

Copied

Following link explains how the driving licence is made up

Driving Licence Explained‌

"SMITHG07173SK9GP" - This is invalid driving licece format.


UK driving licence is made of 16 alpha numeric characters so anything less than or greater will automatically make it  invalid.


Hope this helps

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 30, 2015 Apr 30, 2015

Copy link to clipboard

Copied

It works in the ExtendScript Toolkit as well as in RegexBuddy. The only thing I can think of is that there is some error in the code in Captivate that is making it fail. I am not familiar enough with Captivate. I am sorry I couldn't be more help. -Rick

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 30, 2015 Apr 30, 2015

Copy link to clipboard

Copied

Hi Rick,

That is where I am stuck as well. Don't understand why it would work everywhere else but not in Captivate

Anyway.. thanks for your reply and I appreciate your time and help provided.

I will take this matter to adobe and see if they can help it out.

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 03, 2015 May 03, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 04, 2015 May 04, 2015

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines