Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need RegEx pattern to pull some text from HTML JS Tags.

    Hi,
    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:
    Code:
    <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

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,454
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Examples

    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:

    Code:
    <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:
    Code:
    place_ad_here('A728'),'place_ad_here('ASPON120'),place_ad_here('ROLLOVER'),place_ad_here('A300'),place_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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •