View Full Version : Reg expression help please
01-03-2012, 10:14 PM
I am trying to change the background color of TD's that only the exact text PTO and really do not grasp regex's
<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:
return /PTO/.test( $(this).text() );
but it also changes the background of items like my second element example.
- Yes it should be case sensitive, if possible.
01-03-2012, 10:21 PM
return /[^a-zA-Z]PTO/.test( $(this).text() );
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:
return /([^a-zA-Z]PTO|^PTO)/.test( $(this).text() );
01-03-2012, 10:43 PM
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
01-03-2012, 10:49 PM
ok, im dumb, using /UPTO/ for the UPTO's and using your example for the PTO's worked.
01-03-2012, 10:59 PM
Not to ask a silly question...
If you are generating those <td>'s in PHP code, why not do this in the PHP instead??
01-03-2012, 11:11 PM
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.
01-03-2012, 11:17 PM
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.