View Full Version : Need RegEx pattern to pull some text from HTML JS Tags.

05-21-2009, 08:16 PM
I need to parse an an HTML page and pull what ever values are in these JavaScript tags. There will usually be multiple tags with different values between the single quotes. The value in the next example I need to pull into my array would be 'A728'. Here is an example:

<script type="text/javascript">yld_mgr.place_ad_here('A728');</script>
My RegEx skills are not what I would like and I have found no examples that do this kind of thing.

Thanks in advance

Old Pedant
05-22-2009, 01:48 AM
Give us a few more examples. From that ONE example we could create a regex that's too limiting for your actual general use.

What about multiple line scripts? What about...well, just give us examples. I'd say at least 4 or 5 and as different as you expect to encounter.

05-22-2009, 04:35 PM
The source is an HTML page with all manner of code and text and what not. Sprinkled amongst the source code will be one or more of these tags:

<script type="text/javascript">yld_mgr.place_ad_here('A728');</script>
<script type="text/javascript">yld_mgr.place_ad_here('ASPON120');</script>
<script type="text/javascript">yld_mgr.place_ad_here('ROLLOVER');</script>
<script type="text/javascript">yld_mgr.place_ad_here('A300');</script>
<script type="text/javascript">yld_mgr.place_ad_here('Middle1');</script>
<script type="text/javascript">yld_mgr.place_ad_here('B300');</script>

I can say that there will never be an item immediately preceded by "place_ad_here('" and followed by "');" that I do not want to capture. The set of items I would like to capture from this example would be (A728,ASPON120,ROLLOVER,A300,Middle1,B300)

I am using JavaScript for the RegEx engine and I have gotten to the pattern
place_ad_here\('(.*?)'\) This pattern results in this result:

place_ad_here('A728'),'place_ad_here('ASPON120'),place_ad_here('ROLLOVER'),place_ad_here('A300'),pla ce_ad_here('Middle1'),place_ad_here('B300')
And I could live with that, I could then do some string manipulation on the strings in the array on output and display the desired values.
But is there now way to say give me what ever is between this pattern place_ad_here\(' and this pattern '\) ?

Thank you in advance for taking the time to think about this question.