Forum Moderators: phranque

Message Too Old, No Replies

Regular Expression Help

Rookie needs help with regular expression

         

riospace

7:21 am on Jul 19, 2012 (gmt 0)

10+ Year Member



I am a rookie to the use of regular expressions and have just finished a tutorial, but can not get this simple situation to work.

I have the following script on over 3,000 pages with a different name on each one. I want to use find and replace to change this code site wide.

<script type="text/javascript">
var dhtmlwin = null;
function openThumbnailLink(addr, winWidth, winHeight) {
dhtmlwin = dhtmlmodal.open('ETGfullsizeimagewindow', 'iframe', addr, 'Dianna Agron Photos',
'width=' + winWidth + 'px,height=' + winHeight +
'px,center=1,resize=1,scrolling=1');
dhtmlwin.onclose=function () {
dhtmlwin = null;
return true;
};
}
</script>

I can not figure out how to create a simple regular expression for the part of the code that has different names in it ('Dianna Agron Photos'). I just need someone to tell me what I need to do as far as regular expressions go to find the code on every page with different names in this part of the code. Thanks!

lucy24

11:25 am on Jul 19, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Not enough information. I can't figure out which direction you're going. Do you want to capture a name from somewhere else, and then put it into the script you illustrated? Or do you want to search for the script, including the variable bit? Do you need to capture the variable part for reuse, or just find it?

Is everything else exactly the same?

'ETGfullsizeimagewindow', 'iframe', addr, 'Dianna Agron Photos'
>>
'ETGfullsizeimagewindow', 'iframe', addr, '[^']+'

or . . . '([^']+)' if you need to capture.

Don't forget that literal plus signs and literal parentheses will both need to be escaped if you are searching for them.

riospace

4:01 pm on Jul 19, 2012 (gmt 0)

10+ Year Member



I just need to find it. I just want to find this script on every page and replace it with a new script. Everything is exactly the same in the script on every page except for:

'Dianna Agron Photos'

which has a different name on every page. Thanks!

riospace

7:19 pm on Jul 19, 2012 (gmt 0)

10+ Year Member



Can't seem to figure this simple thing out.

wilderness

7:37 pm on Jul 19, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Pardon my intrusion.

lucy,
This has nothing to do with Apache (another forum might provide better assistance), rather what is being requested is a regex for charcter to replaces script syntax in multiple HTML pages (i. e., 3,000).

riospace,
You haven't provided what software your using for editing HTML or PHP and "regex capabilities" of the software.
Just because your able to gather a desired expression, deosn't necessarily prove that it will function in your software.

FWIW:

This may help (no clue where I saved this from):

Regualar expressions may include quantifiers, which tell how many times and event or string must occur.
> {bottom,top} where bottom and top are numbers that mean the event must occur bottom times and no more than top times.
> {number,} means it has to happen at least number of times.
> {number,} indicates that it must happen exactly number of times.

riospace

8:30 pm on Jul 19, 2012 (gmt 0)

10+ Year Member



Thanks Wilderness, I am using Dreamweaver.

lucy24

9:00 pm on Jul 19, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yup, got that. I think you both missed the

'([^']+)'

which should be all that's necessary. Unless-- shudder!-- those variably-named pieces sometimes contain a literal apostrophe. Then you have to go to a slightly more complicated rule involving \\ for the literal backslash where you escaped the literal apostrophe. (Read that sentence slowly ;))

:: thinking ::

{blahblah} 'John\'s Pictures' {blahblah}

'([^']+(\\'[^']+)*)'

riospace

9:25 pm on Jul 19, 2012 (gmt 0)

10+ Year Member



Thanks Lucy, ([^']+(\\'[^']+)*) worked perfectly and you saved me so much time!