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 7 of 7
  1. #1
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts

    Reg expression help please

    I am trying to change the background color of TD's that only the exact text PTO and really do not grasp regex's

    string/element examples:
    Code:
    <td class="ms-cal-todayitem"> Ward, Daniel M. - PTO - home - im awesome. </td>
    
    <td class="ms-cal-todayitem">Ward, Daniel M. - UPTO - home - im awesome. </td>
    I tried this:

    Code:
    $("td.ms-cal-todayitem").filter(function() {
    return /PTO/.test( $(this).text() );
    }).css("background-color","#C4DBFF")
    but it also changes the background of items like my second element example.
    - Yes it should be case sensitive, if possible.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,554
    Thanks
    80
    Thanked 4,617 Times in 4,581 Posts
    Try this:
    Code:
    $("td.ms-cal-todayitem").filter(
            function() {
                return /[^a-zA-Z]PTO/.test( $(this).text() );
            }
        ).css("background-color","#C4DBFF");
    That says "PTO must be preceded by a non-alphabetic character".

    If you need to handle "PTO" at the start of the string (e.g., "PTO taken by Joe"), then try:
    Code:
    $("td.ms-cal-todayitem").filter(
            function() {
                return /([^a-zA-Z]PTO|^PTO)/.test( $(this).text() );
            }
        ).css("background-color","#C4DBFF");
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    the string itself will always adhere to my examples as they are prebuilt strings that I control ( from a sharepoint form) but I cant control the elements themselves ( again sharepoint)

    I need to match elements with "UPTO" and "PTO" , they will always be in the middle somewhere, and will always be captalized.

    basically I am trying to color code Sharepoint calender entries for planned time off and unplanned time off, so you get the basic idea here. td's with "PTO" get one color and td's with "UPTO" get another color

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    ok, im dumb, using /UPTO/ for the UPTO's and using your example for the PTO's worked.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,554
    Thanks
    80
    Thanked 4,617 Times in 4,581 Posts
    Not to ask a silly question...

    If you are generating those <td>'s in PHP code, why not do this in the PHP instead??
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    im not. the elements are being generated by MS SHarepoint 2007 in c#.net 2.0 and I have no direct server access so I can only use sharepoint designer to build custom pages.

    It doesnt allow you access to code behind and SP doesnt let you use inlineserver side code either, it ignores it and you can only build visual studio solutions if your copy of VS si directly on the sharepoint server ( insane right??)

    hell if I had access to server side code I wouldnt be having this issue

    what you showed me should suffice as long as I run the functions in the correct order.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,554
    Thanks
    80
    Thanked 4,617 Times in 4,581 Posts
    Even the order shouldn't matter.

    The UPTO will never find just PTO and the regexp I gave you for PTO will never find UPTO.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    DanInMa (01-04-2012)


  •  

    Posting Permissions

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