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

[CC][JS]URL Grep at the end of story

Community Beginner ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

Hi guys,

I have a working grep for finding url in an InDesign document and I'd say it finds everything:

app.findGrepPreferences.findWhat="(http|https|Http|Https|rtsp|Rtsp|ftp|www).+?(?=(\\)|\\.|\\,|\\?|\\!|\"|'|;|\\r)*(\\s))";

the only problem is can't find the ones at the end of the story.

Any thoughts?

Thanks,

-CharlesD

TOPICS
Scripting

Views

2.0K

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

Advisor , Jan 31, 2017 Jan 31, 2017

(http|https|Http|Https|rtsp|Rtsp|ftp|www).+?(?=(\\)|\\.|\\,|\\?|\\!|\"|'|;|\\r)*($|\\s)) seems to work.

Votes

Translate

Translate
Guide ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

I hope you are using app.changeGrep();   to change.. if not use this to change for entire document

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
Engaged ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

Hi,

var myDoc = app.activeDocument;

var Stories = app.activeDocument.stories.everyItem().getElements()

for(i=0; i<Stories.length; i++)

{  

app.findGrepPreferences = app.changeGrepPreferences=null;  

app.findGrepPreferences.findWhat= ""; // find code

app.findGrepPreferences.changeTo= "";  // change code

app.changeGrep();

}

Thanks,

Prabu

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.

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
Advisor ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

stab in the dark, as i can't test:

(http|https|Http|Https|rtsp|Rtsp|ftp|www).+?(?=(\\)|\\.|\\,|\\?|\\!|\"|'|;|\\r)*(\\s|\\Z))

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 Beginner ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

@Vamitul

that's exactly how I tried it but '\\z' is a bit of a mystery. Any other options?

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
Advisor ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

It should be capital - Z (not z)

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 Beginner ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

I tried both, no luck

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
People's Champ ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

(http|https|Http|Https|rtsp|Rtsp|ftp|www)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/#-]*[\w@?^=%&/#-])?

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
Advisor ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

(http|https|Http|Https|rtsp|Rtsp|ftp|www).+?(?=(\\)|\\.|\\,|\\?|\\!|\"|'|;|\\r)*($|\\s)) seems to work.

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 Beginner ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

Perfect! I've seen a lot of grep combinations from this forum even from 5 years ago and i always check for new ideas but this one is by far the most reliable. please try it out and let me know its faults so we can improve it for everyone's benefit.

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
LEGEND ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

Hi,

Have you just tried it in a para with 2 www.….com?

(^/)

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
Advisor ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

Actually, I think the absolute best one I've found for urls is: Daring Fireball: An Improved Liberal, Accurate Regex Pattern for Matching URLs

(short version:

(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))

)

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
LEGEND ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

I've just copied/pasted it: It doesn't work! 

(^/)

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 Beginner ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

Vamitul​, the one you posted from Daring Fireball failed on this url:

http://uli​.org/wp-content/uploads/ULIDocuments/Norfolk_PanelReport_Fweb.pdf

It only gets up to this:

http://uli​.org/wp-content/uploads/

If you guys have other patterns that you think is perfect please post it here.

It's time to establish the most reliable pattern once and for all. Should we create a new discussion?

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
Engaged ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

Hi,

Please try this:

(https?://?|www?)[-./\~\w&]+

Thanks,

Prabu G

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.

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 Beginner ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

Thanks for the quick replies. I don't actually use changeGrep because I don't change anything I just have to find those urls and make them as live links. Here are some parts of my code:

app.findGrepPreferences.findWhat="(http|https|Http|Https|rtsp|Rtsp|ftp|www).+?(?=(\\)|\\.|\\,|\\?|\\!|\"|'|;|\\r)*(\\s))";

    if (myDoc.findGrep().length > 0){

        URLlinker(myDoc.findGrep());

    }

function URLlinker(){

  ... do something with with the found urls

}

It finds all the urls except the end of the stories.

I also tried using \\s|\\z but it doesn't find anything. So I had to duplicate the function and just replace '\\s' with '\\z' but it gives me some odd results.

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
Participant ,
Oct 25, 2018 Oct 25, 2018

Copy link to clipboard

Copied

LATEST

Hi,

I tried these both code but not working, can anyone help to find the problem?

var myDoc = app.activeDocument;

app.findGrepPreferences.findWhat="(https?://?|www?)[-./\~\w&]+"; 

    if (myDoc.findGrep().length > 0){ 

        URLlinker(myDoc.findGrep()); 

    } 

function URLlinker(){ 

app.changeGrepPreferences.appliedCharacterStyle="Hyperlink"

app.changeGrep();

}

****************************

var myDoc = app.activeDocument;

var Stories = app.activeDocument.stories.everyItem().getElements()

for(i=0; i<Stories.length; i++)

app.findGrepPreferences = app.changeGrepPreferences=null; 

app.findGrepPreferences.findWhat= "(https?://?|www?)[-./~w&]+"; // find code

app.changeGrepPreferences.appliedCharacterStyle="Hyperlink"

app.changeGrep();

}

Thanks in advance.

by

hasvi

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 Beginner ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

Ok guys I started a new thread:

[CC][JS]Searching for the most reliable URL grep pattern

Please post there your ideas. 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